Merge branch 'main' of https://git.probindo.com/Probindo/database-pertani-web
This commit is contained in:
@@ -0,0 +1,216 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Web\Master;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\Request;
|
||||
use App\Models\Master\JenisKomoditas;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Validator;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
use Illuminate\Support\Str;
|
||||
use Illuminate\Validation\Rule;
|
||||
|
||||
class JenisKomoditasController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$perPage = $request->get('per_page', 10);
|
||||
$search = $request->get('search');
|
||||
|
||||
$jenisKomoditas = JenisKomoditas::with('komoditas')
|
||||
->when($search, function ($query) use ($search) {
|
||||
$query->where(function ($q) use ($search) {
|
||||
$q->where('nama', 'ILIKE', "%{$search}%")
|
||||
->orWhere('path', 'ILIKE', "%{$search}%")
|
||||
->orWhereHas('komoditas', function ($komoditasQuery) use ($search) {
|
||||
$komoditasQuery->where('nama', 'ILIKE', "%{$search}%");
|
||||
});
|
||||
});
|
||||
})
|
||||
->latest()
|
||||
->paginate($perPage);
|
||||
|
||||
$komoditas = Komoditas::orderBy('nama', 'asc')->get();
|
||||
|
||||
return view('master.jeniskomoditas.index', compact(
|
||||
'jenisKomoditas',
|
||||
'komoditas'
|
||||
));
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$validated = $request->validate([
|
||||
'komoditas_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
'exists:master_komoditas,id',
|
||||
],
|
||||
'nama' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('jenis_komoditas', 'nama')
|
||||
->where('komoditas_id', $request->komoditas_id),
|
||||
],
|
||||
], [
|
||||
'komoditas_id.required' => 'Komoditas wajib dipilih.',
|
||||
'komoditas_id.exists' => 'Komoditas yang dipilih tidak valid.',
|
||||
'nama.required' => 'Nama jenis komoditas wajib diisi.',
|
||||
'nama.unique' => 'Nama jenis komoditas sudah tersedia pada komoditas ini.',
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$jenisKomoditas = JenisKomoditas::create([
|
||||
'komoditas_id' => $validated['komoditas_id'],
|
||||
'nama' => $validated['nama'],
|
||||
'created_by' => auth()->id(),
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Data jenis komoditas berhasil disimpan.',
|
||||
'data' => $jenisKomoditas,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error('Gagal menyimpan jenis komoditas', [
|
||||
'error' => $e->getMessage(),
|
||||
'request' => $request->all(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal menyimpan data: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*/
|
||||
public function show(string $id)
|
||||
{
|
||||
try {
|
||||
$jenisKomoditas = JenisKomoditas::with('komoditas')->findOrFail($id);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'data' => $jenisKomoditas,
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Data jenis komoditas tidak ditemukan.',
|
||||
], 404);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, string $id)
|
||||
{
|
||||
$jenisKomoditas = JenisKomoditas::findOrFail($id);
|
||||
|
||||
$validated = $request->validate([
|
||||
'komoditas_id' => [
|
||||
'required',
|
||||
'integer',
|
||||
'exists:master_komoditas,id',
|
||||
],
|
||||
'nama' => [
|
||||
'required',
|
||||
'string',
|
||||
'max:255',
|
||||
Rule::unique('jenis_komoditas', 'nama')
|
||||
->where('komoditas_id', $request->komoditas_id)
|
||||
->ignore($jenisKomoditas->id),
|
||||
],
|
||||
'path' => [
|
||||
'nullable',
|
||||
'string',
|
||||
],
|
||||
], [
|
||||
'komoditas_id.required' => 'Komoditas wajib dipilih.',
|
||||
'komoditas_id.exists' => 'Komoditas yang dipilih tidak valid.',
|
||||
'nama.required' => 'Nama jenis komoditas wajib diisi.',
|
||||
'nama.unique' => 'Nama jenis komoditas sudah tersedia pada komoditas ini.',
|
||||
]);
|
||||
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$jenisKomoditas->update([
|
||||
'komoditas_id' => $validated['komoditas_id'],
|
||||
'nama' => $validated['nama'],
|
||||
'updated_by' => auth()->id(),
|
||||
]);
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Data jenis komoditas berhasil diperbarui.',
|
||||
'data' => $jenisKomoditas->fresh('komoditas'),
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error('Gagal update jenis komoditas', [
|
||||
'error' => $e->getMessage(),
|
||||
'id' => $id,
|
||||
'request' => $request->all(),
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal mengupdate data: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy(string $id)
|
||||
{
|
||||
try {
|
||||
DB::beginTransaction();
|
||||
|
||||
$jenisKomoditas = JenisKomoditas::findOrFail($id);
|
||||
$jenisKomoditas->update(['deleted_by' => auth()->id()]);
|
||||
$jenisKomoditas->delete();
|
||||
|
||||
DB::commit();
|
||||
|
||||
return response()->json([
|
||||
'status' => 'success',
|
||||
'message' => 'Data jenis komoditas berhasil dihapus.',
|
||||
]);
|
||||
} catch (\Throwable $e) {
|
||||
DB::rollBack();
|
||||
|
||||
Log::error('Gagal hapus jenis komoditas', [
|
||||
'error' => $e->getMessage(),
|
||||
'id' => $id,
|
||||
]);
|
||||
|
||||
return response()->json([
|
||||
'status' => 'error',
|
||||
'message' => 'Gagal menghapus data: ' . $e->getMessage(),
|
||||
], 500);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models\Master;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use App\Models\Pertanian\Komoditas;
|
||||
|
||||
class JenisKomoditas extends Model
|
||||
{
|
||||
use HasFactory, SoftDeletes;
|
||||
|
||||
protected $table = 'jenis_komoditas';
|
||||
|
||||
protected $fillable = [
|
||||
'nama',
|
||||
'komoditas_id',
|
||||
'created_by',
|
||||
'updated_by',
|
||||
'deleted_by',
|
||||
];
|
||||
|
||||
public function komoditas()
|
||||
{
|
||||
return $this->belongsTo(Komoditas::class, 'komoditas_id');
|
||||
}
|
||||
}
|
||||
@@ -10,13 +10,14 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uid')->unique();
|
||||
$table->string('name');
|
||||
$table->string('email')->unique();
|
||||
$table->string('username')->unique();
|
||||
$table->string('email')->unique()->nullable();
|
||||
$table->timestamp('email_verified_at')->nullable();
|
||||
$table->string('password');
|
||||
$table->rememberToken();
|
||||
$table->string('role')->nullable();
|
||||
$table->string('uid')->unique();
|
||||
$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');
|
||||
@@ -24,17 +25,6 @@ return new class extends Migration
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
// Schema::create('user_roles', function (Blueprint $table) {
|
||||
// $table->id();
|
||||
// $table->foreignId('user_id')->unique()->constrained('users')->onDelete('cascade');
|
||||
// $table->enum('role_name', ['Super Admin', 'Admin', 'Koordinator', 'Penyuluh', 'Pendamping', 'Petani'])->default('Petani');
|
||||
// $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');
|
||||
// $table->timestamps();
|
||||
// $table->softDeletes();
|
||||
// });
|
||||
|
||||
Schema::create('password_reset_tokens', function (Blueprint $table) {
|
||||
$table->string('email')->primary();
|
||||
$table->string('token');
|
||||
@@ -54,7 +44,6 @@ return new class extends Migration
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
// Schema::dropIfExists('user_roles');
|
||||
Schema::dropIfExists('password_reset_tokens');
|
||||
Schema::dropIfExists('sessions');
|
||||
}
|
||||
|
||||
@@ -23,9 +23,22 @@ return new class extends Migration
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::create('jenis_komoditas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('komoditas_id')->constrained('master_komoditas')->onDelete('cascade');
|
||||
$table->string('nama');
|
||||
$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');
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::create('master_varietas', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->foreignId('komoditas_id')->constrained('master_komoditas')->onDelete('cascade');
|
||||
$table->foreignId('jenis_komoditas_id')->constrained('jenis_komoditas')->onDelete('cascade');
|
||||
$table->string('nama');
|
||||
$table->text('deskripsi')->unique();
|
||||
|
||||
@@ -37,13 +50,11 @@ return new class extends Migration
|
||||
$table->softDeletes();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('master_komoditas');
|
||||
Schema::dropIfExists('master_varietas');
|
||||
Schema::dropIfExists('jenis_komoditas');
|
||||
Schema::dropIfExists('master_komoditas');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -13,6 +13,7 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('map_lahan', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uid')->unique();
|
||||
$table->string('nama');
|
||||
$table->string('status_kepemilikan');
|
||||
|
||||
@@ -21,8 +22,14 @@ return new class extends Migration
|
||||
$table->foreignId('adat_pemilik_id')->nullable()->constrained('adat')->onDelete('set null');
|
||||
|
||||
$table->foreignId('desa_kelurahan_id')->nullable()->constrained('master_desa_kelurahan');
|
||||
$table->string('lat')->nullable();
|
||||
$table->string('long')->nullable();
|
||||
$table->jsonb('path')->nullable();
|
||||
|
||||
$table->boolean('sertifikat')->default(false);
|
||||
$table->boolean('konflik')->default(false);
|
||||
$table->text('deskripsi')->nullable();
|
||||
|
||||
$table->float('luas_lahan', 8)->nullable();
|
||||
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
@@ -33,11 +40,31 @@ return new class extends Migration
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::create('sertifikat_lahan', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uid')->unique();
|
||||
$table->string('nomor_sertifikat');
|
||||
$table->date('tanggal_terbit');
|
||||
$table->date('tanggal_kadaluarsa')->nullable();
|
||||
$table->string('lembaga_penerbit')->nullable();
|
||||
|
||||
$table->foreignId('lahan_id')->constrained('map_lahan')->onDelete('cascade');
|
||||
|
||||
$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');
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
});
|
||||
|
||||
Schema::create('map_tanaman', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uid')->unique();
|
||||
$table->string('nama');
|
||||
|
||||
$table->foreignId('komoditas_id')->constrained('master_komoditas')->onDelete('set null');
|
||||
$table->foreignId('jenis_komoditas_id')->constrained('jenis_komoditas')->onDelete('set null');
|
||||
$table->foreignId('varietas_id')->constrained('master_varietas')->onDelete('set null');
|
||||
$table->foreignId('profile_id')->constrained('profiles')->onDelete('set null');
|
||||
$table->foreignId('lahan_id')->constrained('map_lahan')->onDelete('set null');
|
||||
@@ -46,6 +73,8 @@ return new class extends Migration
|
||||
$table->float('longitude')->nullable();
|
||||
|
||||
$table->string('kondisi_tanaman')->nullable();
|
||||
$table->string('metode_pengumpulan')->nullable();
|
||||
$table->text('deskripsi')->nullable();
|
||||
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
@@ -62,6 +91,7 @@ return new class extends Migration
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('map_tanaman');
|
||||
Schema::dropIfExists('sertifikat_lahan');
|
||||
Schema::dropIfExists('map_lahan');
|
||||
}
|
||||
};
|
||||
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('map_lahan', function (Blueprint $table) {
|
||||
$table->jsonb('path')->nullable()->change();
|
||||
});
|
||||
|
||||
Schema::table('master_provinsi', function (Blueprint $table) {
|
||||
$table->jsonb('path')->nullable()->change();
|
||||
});
|
||||
|
||||
Schema::table('master_kabupaten_kota', function (Blueprint $table) {
|
||||
$table->jsonb('path')->nullable()->change();
|
||||
});
|
||||
|
||||
Schema::table('master_kecamatan', function (Blueprint $table) {
|
||||
$table->jsonb('path')->nullable()->change();
|
||||
});
|
||||
|
||||
Schema::table('master_desa_kelurahan', function (Blueprint $table) {
|
||||
$table->jsonb('path')->nullable()->change();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
@@ -29,9 +29,15 @@ return new class extends Migration
|
||||
$table->foreignId('tabel_id')->constrained('ekosistem_basis_data_tabel')->restrictOnDelete();
|
||||
$table->string('kolom');
|
||||
$table->string('label');
|
||||
$table->enum('tipe', ['varchar', 'integer', 'float', 'boolean', 'date', 'datetime', 'text'])->default('varchar');
|
||||
$table->enum('tipe', ['varchar', 'integer', 'float', 'boolean', 'date', 'datetime', 'text', 'foreign_key', 'enum'])->default('varchar');
|
||||
$table->jsonb('validasi')->nullable();
|
||||
$table->integer('urutan')->default(1);
|
||||
$table->string('relasi_tabel')->nullable();
|
||||
$table->string('relasi_kolom_id')->nullable();
|
||||
$table->string('relasi_kolom_label')->nullable();
|
||||
$table->boolean('is_active')->default('true');
|
||||
$table->boolean('is_browse')->default('false');
|
||||
$table->jsonb('enum_opsi')->nullable();
|
||||
|
||||
$table->timestamps();
|
||||
$table->softDeletes();
|
||||
@@ -60,6 +66,8 @@ return new class extends Migration
|
||||
$table->date('value_date')->nullable();
|
||||
$table->datetime('value_datetime')->nullable();
|
||||
$table->text('value_text')->nullable();
|
||||
$table->integer('value_relasi')->nullable();
|
||||
$table->string('value_enum')->nullable();
|
||||
|
||||
$table->foreignId('created_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
$table->foreignId('updated_by')->nullable()->constrained('users')->onDelete('set null');
|
||||
|
||||
@@ -1,25 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('profiles', function (Blueprint $table) {
|
||||
$table->foreignId('adat_id')->nullable()->constrained('adat');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -13,9 +13,11 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('ekosistem_petani_cpm', function (Blueprint $table) {
|
||||
$table->id();
|
||||
|
||||
$table->string('uid')->unique();
|
||||
$table->foreignId('program_id')->nullable()->constrained('core_program')->nullOnDelete();
|
||||
$table->string('nama');
|
||||
$table->boolean('jenis_kelamin');
|
||||
$table->string('tempat_lahir')->nullable();
|
||||
$table->date('tanggal_lahir');
|
||||
|
||||
$table->string('pendidikan_terakhir')->nullable();
|
||||
@@ -28,11 +30,17 @@ return new class extends Migration
|
||||
$table->float('lama_bertani', 8)->nullable();
|
||||
$table->float('luas_lahan', 8)->nullable();
|
||||
|
||||
$table->string('dusun_rt_rw')->nullable();
|
||||
$table->string('nomor_telepon')->nullable();
|
||||
$table->string('foto')->nullable();
|
||||
|
||||
$table->string('pekerjaan_sampingan')->nullable();
|
||||
$table->foreignId('komoditas_sampingan_id')->nullable()->constrained('master_komoditas');
|
||||
$table->float('lama_bertani_sampingan', 8)->nullable();
|
||||
$table->float('luas_lahan_sampingan', 8)->nullable();
|
||||
|
||||
|
||||
|
||||
$table->string('status_perkawinan')->nullable();
|
||||
$table->string('status_keluarga')->nullable();
|
||||
$table->integer('jumlah_tanggungan')->nullable();
|
||||
@@ -48,9 +56,6 @@ return new class extends Migration
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('ekosistem_petani_cpm');
|
||||
|
||||
@@ -1,55 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('ekosistem_basis_data_kolom', function (Blueprint $table) {
|
||||
$table->string('relasi_tabel')->nullable();
|
||||
$table->string('relasi_kolom_id')->nullable();
|
||||
$table->string('relasi_kolom_label')->nullable();
|
||||
|
||||
$table->jsonb('enum_opsi')->nullable();
|
||||
});
|
||||
|
||||
DB::statement("alter table public.ekosistem_basis_data_kolom drop constraint ekosistem_basis_data_kolom_tipe_check;");
|
||||
DB::statement("
|
||||
alter table public.ekosistem_basis_data_kolom add constraint ekosistem_basis_data_kolom_tipe_check check (((tipe)::text = any
|
||||
((array[
|
||||
'varchar'::character varying,
|
||||
'integer'::character varying,
|
||||
'float'::character varying,
|
||||
'boolean'::character varying,
|
||||
'date'::character varying,
|
||||
'datetime'::character varying,
|
||||
'text'::character varying,
|
||||
'foreign_key'::character varying,
|
||||
'enum'::character varying
|
||||
])::text[])))
|
||||
");
|
||||
|
||||
Schema::table('ekosistem_basis_data_value', function (Blueprint $table) {
|
||||
$table->integer('value_relasi')->nullable();
|
||||
$table->string('value_enum')->nullable();
|
||||
});
|
||||
|
||||
Schema::table('ekosistem_petani_cpm', function (Blueprint $table) {
|
||||
$table->foreignId('program_id')->nullable()->constrained('core_program')->nullOnDelete();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -13,6 +13,7 @@ return new class extends Migration
|
||||
{
|
||||
Schema::create('ekosistem_lahan_cpcl', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('uid')->unique();
|
||||
$table->string('nama');
|
||||
$table->string('status_kepemilikan');
|
||||
|
||||
|
||||
@@ -1,27 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('ekosistem_basis_data_kolom', function (Blueprint $table) {
|
||||
$table->boolean('is_active')->default('true');
|
||||
$table->boolean('is_browse')->default('false');
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
}
|
||||
};
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::table('map_lahan', function (Blueprint $table) {
|
||||
//
|
||||
$table->string('uid')->unique(); // LH-1234567890&0987654321 (sepuluh digit user - 10 digit lahan)
|
||||
});
|
||||
|
||||
Schema::table('map_tanaman', function(Blueprint $table){
|
||||
$table->string('uid')->unique(); //// LH-1234567890&0987654321&5432167890
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::table('map_lahan', function (Blueprint $table) {
|
||||
$table->dropUnique(['uid']);
|
||||
$table->dropColumn(['uid']);
|
||||
});
|
||||
|
||||
Schema::table('map_tanaman', function (Blueprint $table) {
|
||||
$table->dropUnique(['uid']);
|
||||
$table->dropColumn(['uid']);
|
||||
});
|
||||
}
|
||||
};
|
||||
@@ -15,17 +15,18 @@ class AdminUserSeeder extends Seeder
|
||||
public function run(): void
|
||||
{
|
||||
DB::table('users')->insert([
|
||||
'uid' => 'AD-1234567891',
|
||||
'name' => 'Admin',
|
||||
'username' => 'admin',
|
||||
'email' => 'admin@example.com',
|
||||
'email_verified_at' => now(),
|
||||
'password' => Hash::make('Asalada123'),
|
||||
'role' => 'super_admin',
|
||||
'uid' => 'AD-1234567891',
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
]);
|
||||
|
||||
Db::table('profiles')->insert([
|
||||
DB::table('profiles')->insert([
|
||||
'user_id' => 1,
|
||||
'role' => 'super_admin',
|
||||
'nama' => 'Admin',
|
||||
@@ -44,7 +45,6 @@ class AdminUserSeeder extends Seeder
|
||||
'updated_by' => 1,
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
'adat_id' => null,
|
||||
'user_uid' => 'AD-1234567891',
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasAddJenisKomoditas" aria-labelledby="offcanvasAddJenisKomoditasLabel">
|
||||
<div class="offcanvas-header border-bottom">
|
||||
<h5 id="offcanvasAddJenisKomoditasLabel" class="offcanvas-title">Tambah Jenis Komoditas</h5>
|
||||
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="offcanvas-body mx-0 flex-grow-0 p-6 h-100">
|
||||
<form class="add-new-jeniskomoditas pt-0" id="addNewJenisKomoditasForm" action="{{ route('jenis-komoditas.store') }}" method="POST">
|
||||
@csrf
|
||||
|
||||
<div class="mb-6 form-control-validation">
|
||||
<label class="form-label" for="add-jenis-komoditas-komoditas">
|
||||
Komoditas <span class="text-danger">*</span>
|
||||
</label>
|
||||
<select id="add-jenis-komoditas-komoditas" name="komoditas_id" class="select2 form-select" data-placeholder="Pilih Komoditas">
|
||||
<option value=""></option>
|
||||
@foreach($komoditas as $item)
|
||||
<option value="{{ $item->id }}">{{ $item->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 form-control-validation">
|
||||
<label class="form-label" for="add-jenis-komoditas-name">
|
||||
Nama Jenis Komoditas <span class="text-danger">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="add-jenis-komoditas-name"
|
||||
placeholder="Contoh: Kopi Arabika"
|
||||
name="nama"
|
||||
autocomplete="off" />
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<button type="submit" class="btn btn-primary me-3 data-submit">Submit</button>
|
||||
<button type="reset" class="btn btn-label-danger" data-bs-dismiss="offcanvas">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,45 @@
|
||||
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasEditJenisKomoditas" aria-labelledby="offcanvasEditJenisKomoditasLabel">
|
||||
<div class="offcanvas-header border-bottom">
|
||||
<h5 id="offcanvasEditJenisKomoditasLabel" class="offcanvas-title">Edit Jenis Komoditas</h5>
|
||||
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="offcanvas-body mx-0 flex-grow-0 p-6 h-100">
|
||||
<form class="edit-jeniskomoditas pt-0" id="editJenisKomoditasForm" method="POST">
|
||||
@csrf
|
||||
@method('PUT')
|
||||
|
||||
<input type="hidden" id="edit-jenis-komoditas-id" name="id">
|
||||
|
||||
<div class="mb-6 form-control-validation">
|
||||
<label class="form-label" for="edit-jenis-komoditas-komoditas">
|
||||
Komoditas <span class="text-danger">*</span>
|
||||
</label>
|
||||
<select id="edit-jenis-komoditas-komoditas" name="komoditas_id" class="select2 form-select" data-placeholder="Pilih Komoditas">
|
||||
<option value=""></option>
|
||||
@foreach($komoditas as $item)
|
||||
<option value="{{ $item->id }}">{{ $item->nama }}</option>
|
||||
@endforeach
|
||||
</select>
|
||||
</div>
|
||||
|
||||
<div class="mb-6 form-control-validation">
|
||||
<label class="form-label" for="edit-jenis-komoditas-name">
|
||||
Nama Jenis Komoditas <span class="text-danger">*</span>
|
||||
</label>
|
||||
<input
|
||||
type="text"
|
||||
class="form-control"
|
||||
id="edit-jenis-komoditas-name"
|
||||
placeholder="Contoh: Kopi Arabika"
|
||||
name="nama"
|
||||
autocomplete="off" />
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<button type="submit" class="btn btn-primary me-3 data-submit">Update</button>
|
||||
<button type="reset" class="btn btn-label-danger" data-bs-dismiss="offcanvas">Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
@@ -0,0 +1,485 @@
|
||||
@extends('layout.main')
|
||||
|
||||
@section('content')
|
||||
<div class="container-xxl flex-grow-1 container-p-y">
|
||||
|
||||
<div class="card">
|
||||
<div class="card-header border-bottom">
|
||||
<div class="d-flex flex-column flex-md-row justify-content-between align-items-md-center gap-3">
|
||||
<div>
|
||||
<h5 class="card-title mb-0">Jenis Komoditas</h5>
|
||||
<small class="text-muted">Kelola data jenis komoditas</small>
|
||||
</div>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-primary"
|
||||
data-bs-toggle="offcanvas"
|
||||
data-bs-target="#offcanvasAddJenisKomoditas">
|
||||
<i class="ti tabler-plus me-1"></i>
|
||||
Tambah Jenis Komoditas
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card-body border-bottom">
|
||||
<form
|
||||
method="GET"
|
||||
action="{{ route('jenis-komoditas.index') }}"
|
||||
class="row g-3 align-items-center justify-content-between">
|
||||
|
||||
<div class="col-md-auto">
|
||||
<div class="d-flex align-items-center">
|
||||
<label class="me-2 text-nowrap">Show</label>
|
||||
<select name="per_page" class="form-select form-select-sm w-auto" onchange="this.form.submit()">
|
||||
@foreach([10, 25, 50, 100] as $limit)
|
||||
<option value="{{ $limit }}" {{ (int) request('per_page', 10) === $limit ? 'selected' : '' }}>
|
||||
{{ $limit }}
|
||||
</option>
|
||||
@endforeach
|
||||
</select>
|
||||
<label class="ms-2 text-nowrap">entries</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="col-md-auto">
|
||||
<div class="input-group input-group-sm">
|
||||
<input
|
||||
type="text"
|
||||
name="search"
|
||||
class="form-control"
|
||||
placeholder="Cari jenis komoditas..."
|
||||
value="{{ request('search') }}">
|
||||
|
||||
@if(request('search'))
|
||||
<a href="{{ route('jenis-komoditas.index', ['per_page' => request('per_page', 10)]) }}"
|
||||
class="btn btn-outline-secondary">
|
||||
<i class="ti tabler-x"></i>
|
||||
</a>
|
||||
@endif
|
||||
|
||||
<button type="submit" class="btn btn-outline-primary">
|
||||
<i class="ti tabler-search"></i>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="table-responsive text-nowrap">
|
||||
<table class="table table-hover">
|
||||
<thead class="border-top">
|
||||
<tr>
|
||||
<th style="width: 70px;">No</th>
|
||||
<th>Nama Jenis Komoditas</th>
|
||||
<th>Komoditas</th>
|
||||
<th class="text-center" style="width: 160px;">Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
|
||||
<tbody>
|
||||
@forelse($jenisKomoditas as $index => $jenis)
|
||||
@php
|
||||
$komoditasNama = $jenis->komoditas->nama ?? '-';
|
||||
$words = preg_split('/\s+/', trim($komoditasNama));
|
||||
$initials = collect($words)
|
||||
->filter()
|
||||
->map(fn($word) => strtoupper(substr($word, 0, 1)))
|
||||
->take(2)
|
||||
->implode('');
|
||||
|
||||
$states = ['success', 'danger', 'warning', 'info', 'primary', 'secondary'];
|
||||
$state = $states[$jenis->id % count($states)];
|
||||
@endphp
|
||||
|
||||
<tr>
|
||||
<td>{{ $jenisKomoditas->firstItem() + $index }}</td>
|
||||
|
||||
<td>
|
||||
<div class="d-flex justify-content-start align-items-center">
|
||||
<div class="avatar-wrapper me-3">
|
||||
<div class="avatar avatar-sm">
|
||||
<span class="avatar-initial rounded-circle bg-label-{{ $state }}">
|
||||
{{ $initials ?: 'JK' }}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="d-flex flex-column">
|
||||
<span class="fw-medium text-heading">{{ $jenis->nama }}</span>
|
||||
<small class="text-muted">ID: {{ $jenis->id }}</small>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<span class="badge bg-label-secondary">
|
||||
{{ $komoditasNama }}
|
||||
</span>
|
||||
</td>
|
||||
|
||||
<td>
|
||||
<div class="d-flex justify-content-center align-items-center">
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-icon btn-text-secondary rounded-pill view-record"
|
||||
data-id="{{ $jenis->id }}"
|
||||
title="Lihat">
|
||||
<i class="ti tabler-eye ti-md"></i>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-icon btn-text-secondary rounded-pill edit-record"
|
||||
data-id="{{ $jenis->id }}"
|
||||
title="Edit">
|
||||
<i class="ti tabler-edit ti-md"></i>
|
||||
</button>
|
||||
|
||||
<button
|
||||
type="button"
|
||||
class="btn btn-icon btn-text-secondary rounded-pill delete-record"
|
||||
data-id="{{ $jenis->id }}"
|
||||
data-nama="{{ $jenis->nama }}"
|
||||
title="Hapus">
|
||||
<i class="ti tabler-trash ti-md"></i>
|
||||
</button>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@empty
|
||||
<tr>
|
||||
<td colspan="5" class="text-center py-5">
|
||||
<div class="d-flex flex-column align-items-center">
|
||||
<i class="ti tabler-database-off ti-lg mb-2 text-muted"></i>
|
||||
<span class="text-muted">Tidak ada data ditemukan.</span>
|
||||
</div>
|
||||
</td>
|
||||
</tr>
|
||||
@endforelse
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
@if($jenisKomoditas->hasPages())
|
||||
<div class="card-footer d-flex justify-content-center justify-content-md-end border-top">
|
||||
{{ $jenisKomoditas->appends(request()->query())->links('pagination::bootstrap-5') }}
|
||||
</div>
|
||||
@endif
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@include('master.jeniskomoditas.add')
|
||||
@include('master.jeniskomoditas.edit')
|
||||
@include('master.jeniskomoditas.view')
|
||||
@endsection
|
||||
|
||||
|
||||
@push('scripts')
|
||||
<script>
|
||||
'use strict';
|
||||
|
||||
$(function () {
|
||||
const csrfToken = "{{ csrf_token() }}";
|
||||
const baseUrl = "{{ url('jenis-komoditas') }}";
|
||||
|
||||
const offcanvasAdd = new bootstrap.Offcanvas(document.getElementById('offcanvasAddJenisKomoditas'));
|
||||
const offcanvasEdit = new bootstrap.Offcanvas(document.getElementById('offcanvasEditJenisKomoditas'));
|
||||
const offcanvasView = new bootstrap.Offcanvas(document.getElementById('offcanvasViewJenisKomoditas'));
|
||||
|
||||
$.ajaxSetup({
|
||||
headers: {
|
||||
'X-CSRF-TOKEN': csrfToken
|
||||
}
|
||||
});
|
||||
|
||||
$('.select2').each(function () {
|
||||
const $this = $(this);
|
||||
|
||||
$this.wrap('<div class="position-relative"></div>').select2({
|
||||
dropdownParent: $this.parent(),
|
||||
placeholder: $this.data('placeholder') || 'Pilih data',
|
||||
allowClear: true,
|
||||
width: '100%'
|
||||
});
|
||||
});
|
||||
|
||||
$.validator.setDefaults({
|
||||
errorElement: 'div',
|
||||
errorClass: 'invalid-feedback',
|
||||
highlight: function (element) {
|
||||
$(element).addClass('is-invalid');
|
||||
},
|
||||
unhighlight: function (element) {
|
||||
$(element).removeClass('is-invalid');
|
||||
},
|
||||
errorPlacement: function (error, element) {
|
||||
if (element.hasClass('select2-hidden-accessible')) {
|
||||
error.insertAfter(element.next('.select2-container'));
|
||||
} else {
|
||||
error.appendTo(element.closest('.form-control-validation'));
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('.select2').on('change', function () {
|
||||
const $form = $(this).closest('form');
|
||||
|
||||
if ($form.data('validator')) {
|
||||
$(this).valid();
|
||||
}
|
||||
});
|
||||
|
||||
function showSuccess(title = 'Berhasil!', text = 'Data berhasil diproses') {
|
||||
return Swal.fire({
|
||||
icon: 'success',
|
||||
title,
|
||||
text,
|
||||
showConfirmButton: false,
|
||||
timer: 1500,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
});
|
||||
}
|
||||
|
||||
function showError(xhr, fallback = 'Terjadi kesalahan sistem.') {
|
||||
let message = fallback;
|
||||
|
||||
if (xhr.responseJSON?.message) {
|
||||
message = xhr.responseJSON.message;
|
||||
}
|
||||
|
||||
if (xhr.responseJSON?.errors) {
|
||||
message = Object.values(xhr.responseJSON.errors).flat().join('<br>');
|
||||
}
|
||||
|
||||
return Swal.fire({
|
||||
icon: 'error',
|
||||
title: 'Gagal!',
|
||||
html: message,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
});
|
||||
}
|
||||
|
||||
function resetForm($form) {
|
||||
if (!$form.length) return;
|
||||
|
||||
$form[0].reset();
|
||||
|
||||
if ($form.data('validator')) {
|
||||
$form.validate().resetForm();
|
||||
}
|
||||
|
||||
$form.find('.is-invalid').removeClass('is-invalid');
|
||||
|
||||
$form.find('.select2').each(function () {
|
||||
$(this).val('').trigger('change.select2');
|
||||
});
|
||||
}
|
||||
|
||||
function setButtonLoading($button, isLoading, text = 'Menyimpan...') {
|
||||
if (isLoading) {
|
||||
$button
|
||||
.data('original-text', $button.html())
|
||||
.prop('disabled', true)
|
||||
.html(`<span class="spinner-border spinner-border-sm me-1"></span>${text}`);
|
||||
} else {
|
||||
$button
|
||||
.prop('disabled', false)
|
||||
.html($button.data('original-text'));
|
||||
}
|
||||
}
|
||||
|
||||
$('#addNewJenisKomoditasForm').validate({
|
||||
rules: {
|
||||
komoditas_id: {
|
||||
required: true
|
||||
},
|
||||
nama: {
|
||||
required: true,
|
||||
maxlength: 255
|
||||
}
|
||||
},
|
||||
messages: {
|
||||
komoditas_id: {
|
||||
required: 'Komoditas wajib dipilih'
|
||||
},
|
||||
nama: {
|
||||
required: 'Nama jenis komoditas wajib diisi',
|
||||
maxlength: 'Nama maksimal 255 karakter'
|
||||
}
|
||||
},
|
||||
submitHandler: function (form, event) {
|
||||
event.preventDefault();
|
||||
|
||||
const $form = $(form);
|
||||
const $button = $form.find('button[type="submit"]');
|
||||
|
||||
setButtonLoading($button, true);
|
||||
|
||||
$.ajax({
|
||||
url: $form.attr('action'),
|
||||
type: 'POST',
|
||||
data: $form.serialize(),
|
||||
success: function (res) {
|
||||
offcanvasAdd.hide();
|
||||
|
||||
showSuccess(
|
||||
'Berhasil!',
|
||||
res.message || 'Data jenis komoditas berhasil disimpan'
|
||||
).then(() => window.location.reload());
|
||||
},
|
||||
error: function (xhr) {
|
||||
showError(xhr, 'Gagal menyimpan data jenis komoditas');
|
||||
},
|
||||
complete: function () {
|
||||
setButtonLoading($button, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#offcanvasAddJenisKomoditas').on('hidden.bs.offcanvas', function () {
|
||||
resetForm($('#addNewJenisKomoditasForm'));
|
||||
});
|
||||
|
||||
$(document).on('click', '.edit-record', function () {
|
||||
const id = $(this).data('id');
|
||||
const $form = $('#editJenisKomoditasForm');
|
||||
|
||||
resetForm($form);
|
||||
|
||||
$.ajax({
|
||||
url: `${baseUrl}/${id}`,
|
||||
type: 'GET',
|
||||
success: function (res) {
|
||||
const data = res.data || res;
|
||||
|
||||
$('#edit-jenis-komoditas-id').val(data.id);
|
||||
$('#edit-jenis-komoditas-komoditas').val(data.komoditas_id).trigger('change');
|
||||
$('#edit-jenis-komoditas-name').val(data.nama);
|
||||
|
||||
offcanvasEdit.show();
|
||||
},
|
||||
error: function (xhr) {
|
||||
showError(xhr, 'Terjadi kesalahan saat mengambil data edit');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$('#editJenisKomoditasForm').validate({
|
||||
rules: {
|
||||
komoditas_id: {
|
||||
required: true
|
||||
},
|
||||
nama: {
|
||||
required: true,
|
||||
maxlength: 255
|
||||
}
|
||||
},
|
||||
messages: {
|
||||
komoditas_id: {
|
||||
required: 'Komoditas wajib dipilih'
|
||||
},
|
||||
nama: {
|
||||
required: 'Nama jenis komoditas wajib diisi',
|
||||
maxlength: 'Nama maksimal 255 karakter'
|
||||
}
|
||||
},
|
||||
submitHandler: function (form, event) {
|
||||
event.preventDefault();
|
||||
|
||||
const $form = $(form);
|
||||
const id = $('#edit-jenis-komoditas-id').val();
|
||||
const $button = $form.find('button[type="submit"]');
|
||||
|
||||
setButtonLoading($button, true, 'Mengupdate...');
|
||||
|
||||
$.ajax({
|
||||
url: `${baseUrl}/${id}`,
|
||||
type: 'POST',
|
||||
data: $form.serialize(),
|
||||
success: function (res) {
|
||||
offcanvasEdit.hide();
|
||||
|
||||
showSuccess(
|
||||
'Updated!',
|
||||
res.message || 'Data jenis komoditas berhasil diperbarui'
|
||||
).then(() => window.location.reload());
|
||||
},
|
||||
error: function (xhr) {
|
||||
showError(xhr, 'Gagal mengupdate data jenis komoditas');
|
||||
},
|
||||
complete: function () {
|
||||
setButtonLoading($button, false);
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
$('#offcanvasEditJenisKomoditas').on('hidden.bs.offcanvas', function () {
|
||||
resetForm($('#editJenisKomoditasForm'));
|
||||
});
|
||||
|
||||
$(document).on('click', '.view-record', function () {
|
||||
const id = $(this).data('id');
|
||||
|
||||
$.ajax({
|
||||
url: `${baseUrl}/${id}`,
|
||||
type: 'GET',
|
||||
success: function (res) {
|
||||
const data = res.data || res;
|
||||
|
||||
$('#view-jenis-komoditas-komoditas').val(data.komoditas?.nama || data.nama_komoditas || '-');
|
||||
$('#view-jenis-komoditas-name').val(data.nama || '-');
|
||||
|
||||
offcanvasView.show();
|
||||
},
|
||||
error: function (xhr) {
|
||||
showError(xhr, 'Terjadi kesalahan saat mengambil detail data');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '.delete-record', function () {
|
||||
const id = $(this).data('id');
|
||||
const nama = $(this).data('nama') || 'data ini';
|
||||
|
||||
Swal.fire({
|
||||
title: 'Apakah Anda yakin?',
|
||||
text: `Jenis Komoditas "${nama}" akan dihapus secara permanen.`,
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
confirmButtonText: 'Ya, Hapus!',
|
||||
cancelButtonText: 'Batal',
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-primary me-3',
|
||||
cancelButton: 'btn btn-label-secondary'
|
||||
},
|
||||
buttonsStyling: false
|
||||
}).then(function (result) {
|
||||
if (!result.isConfirmed) return;
|
||||
|
||||
$.ajax({
|
||||
url: `${baseUrl}/${id}`,
|
||||
type: 'DELETE',
|
||||
success: function (res) {
|
||||
showSuccess(
|
||||
'Terhapus!',
|
||||
res.message || 'Data jenis komoditas berhasil dihapus'
|
||||
).then(() => window.location.reload());
|
||||
},
|
||||
error: function (xhr) {
|
||||
showError(xhr, 'Gagal menghapus data jenis komoditas');
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
</script>
|
||||
@endpush
|
||||
@@ -0,0 +1,24 @@
|
||||
<div class="offcanvas offcanvas-end" tabindex="-1" id="offcanvasViewJenisKomoditas" aria-labelledby="offcanvasViewJenisKomoditasLabel">
|
||||
<div class="offcanvas-header border-bottom">
|
||||
<h5 id="offcanvasViewJenisKomoditasLabel" class="offcanvas-title">Detail Jenis Komoditas</h5>
|
||||
<button type="button" class="btn-close text-reset" data-bs-dismiss="offcanvas" aria-label="Close"></button>
|
||||
</div>
|
||||
|
||||
<div class="offcanvas-body mx-0 flex-grow-0 p-6 h-100">
|
||||
<div class="mb-6">
|
||||
<label class="form-label">Komoditas</label>
|
||||
<input type="text" class="form-control" id="view-jenis-komoditas-komoditas" readonly>
|
||||
</div>
|
||||
|
||||
<div class="mb-6">
|
||||
<label class="form-label">Nama Jenis Komoditas</label>
|
||||
<input type="text" class="form-control" id="view-jenis-komoditas-name" readonly>
|
||||
</div>
|
||||
|
||||
<div class="mt-8">
|
||||
<button type="button" class="btn btn-label-secondary" data-bs-dismiss="offcanvas">
|
||||
Tutup
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
@@ -85,6 +85,8 @@ Route::middleware('auth')
|
||||
Route::put('/komoditas/{id}', [App\Http\Controllers\Web\Master\KomoditasController::class, 'update'])->name('komoditas.update');
|
||||
Route::delete('/komoditas/{id}', [App\Http\Controllers\Web\Master\KomoditasController::class, 'destroy'])->name('komoditas.destroy');
|
||||
|
||||
Route::resource('jenis-komoditas', App\Http\Controllers\Web\Master\JenisKomoditasController::class);
|
||||
|
||||
Route::get('/keluarga', [App\Http\Controllers\Web\Master\KeluargaController::class, 'index'])->name('keluarga.index');
|
||||
Route::get('/keluarga/add', [App\Http\Controllers\Web\Master\KeluargaController::class, 'create'])->name('keluarga.create');
|
||||
Route::post('/keluarga', [App\Http\Controllers\Web\Master\KeluargaController::class, 'store'])->name('keluarga.store');
|
||||
|
||||
Reference in New Issue
Block a user