Merge branch 'main' of https://git.probindo.com/Probindo/database-pertani-web
This commit is contained in:
@@ -13,6 +13,7 @@ use Illuminate\Http\JsonResponse;
|
|||||||
use App\Models\Ekosistem\PetaniCPM;
|
use App\Models\Ekosistem\PetaniCPM;
|
||||||
use App\Models\Wilayah\Provinsi;
|
use App\Models\Wilayah\Provinsi;
|
||||||
use App\Models\Pertanian\Komoditas;
|
use App\Models\Pertanian\Komoditas;
|
||||||
|
use App\Models\Core\Program;
|
||||||
|
|
||||||
use App\Enums\Pendidikan;
|
use App\Enums\Pendidikan;
|
||||||
use App\Enums\Pekerjaan;
|
use App\Enums\Pekerjaan;
|
||||||
@@ -30,15 +31,34 @@ class PetaniCPMController extends Controller
|
|||||||
$perPage = $request->query('per_page', 10);
|
$perPage = $request->query('per_page', 10);
|
||||||
$search = strtolower($request->query('search', ''));
|
$search = strtolower($request->query('search', ''));
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
$program = null;
|
||||||
|
$programList = Program::get();
|
||||||
|
if (app()->has('SystemProgram')) {
|
||||||
|
$program = app('SystemProgram');
|
||||||
|
} else {
|
||||||
|
if ($request->has('program_id') && $request->query('program_id')) {
|
||||||
|
$programId = $request->query('program_id');
|
||||||
|
$program = Program::find($programId);
|
||||||
|
if (!$program) {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$petani = PetaniCPM::when($search, function ($query, $search) {
|
$petani = PetaniCPM::when($search, function ($query, $search) {
|
||||||
return $query->where('nama', 'like', "%{$search}%");
|
return $query->where('nama', 'like', "%{$search}%");
|
||||||
})
|
})
|
||||||
|
->when($program, function ($query) use ($program) {
|
||||||
|
return $query->where('program_id', $program->id);
|
||||||
|
})
|
||||||
->paginate($perPage);
|
->paginate($perPage);
|
||||||
|
|
||||||
return view('ekosistem.petani-cpm.index', compact('petani'));
|
return view('ekosistem.petani-cpm.index', compact('petani', 'program', 'programList'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function create(): View
|
public function create(Request $request): View
|
||||||
{
|
{
|
||||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
abort(403);
|
abort(403);
|
||||||
@@ -52,8 +72,21 @@ class PetaniCPMController extends Controller
|
|||||||
$provinsi = Provinsi::all();
|
$provinsi = Provinsi::all();
|
||||||
$komoditas = Komoditas::all();
|
$komoditas = Komoditas::all();
|
||||||
|
|
||||||
|
$program = null;
|
||||||
|
if (app()->has('SystemProgram')) {
|
||||||
|
$program = app('SystemProgram');
|
||||||
|
} else {
|
||||||
|
if ($request->has('program_id') && $request->query('program_id')) {
|
||||||
|
$programId = $request->query('program_id');
|
||||||
|
$program = Program::find($programId);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (!$program) {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
|
||||||
return view('ekosistem.petani-cpm.add', compact('pendidikan', 'pekerjaan',
|
return view('ekosistem.petani-cpm.add', compact('pendidikan', 'pekerjaan',
|
||||||
'pernikahan', 'statusKeluarga', 'provinsi', 'komoditas'));
|
'pernikahan', 'statusKeluarga', 'provinsi', 'komoditas', 'program'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -65,6 +98,20 @@ class PetaniCPMController extends Controller
|
|||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app()->has('SystemProgram')) {
|
||||||
|
$program = app('SystemProgram');
|
||||||
|
} else {
|
||||||
|
if ($request->has('program_id') && $request->query('program_id')) {
|
||||||
|
$programId = $request->query('program_id');
|
||||||
|
$program = Program::find($programId);
|
||||||
|
if (!$program) {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$validatedData = $request->validate([
|
$validatedData = $request->validate([
|
||||||
'nama' => ['required','string','max:255'],
|
'nama' => ['required','string','max:255'],
|
||||||
'jenis_kelamin' => ['required','boolean'],
|
'jenis_kelamin' => ['required','boolean'],
|
||||||
@@ -88,16 +135,17 @@ class PetaniCPMController extends Controller
|
|||||||
]);
|
]);
|
||||||
|
|
||||||
PetaniCPM::create([...$validatedData,
|
PetaniCPM::create([...$validatedData,
|
||||||
|
'program_id' => $program->id,
|
||||||
'created_by' => auth()->id(),
|
'created_by' => auth()->id(),
|
||||||
'updated_by' => auth()->id()]);
|
'updated_by' => auth()->id()]);
|
||||||
|
|
||||||
return redirect()->route('petani-cpm.index')->with('success', 'Data petani CPM berhasil ditambahkan.');
|
return redirect()->route('petani-cpm.index', ['program_id' => $program->id])->with('success', 'Data petani CPM berhasil ditambahkan.');
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Display the specified resource.
|
* Display the specified resource.
|
||||||
*/
|
*/
|
||||||
public function show(string $id)
|
public function show(string $id): View
|
||||||
{
|
{
|
||||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
abort(403);
|
abort(403);
|
||||||
@@ -111,12 +159,26 @@ class PetaniCPMController extends Controller
|
|||||||
/**
|
/**
|
||||||
* Show the form for editing the specified resource.
|
* Show the form for editing the specified resource.
|
||||||
*/
|
*/
|
||||||
public function edit(string $id)
|
public function edit(Request $request, string $id): View
|
||||||
{
|
{
|
||||||
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
if (!Gate::any(['super_admin', 'admin', 'fasilitator'])) {
|
||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app()->has('SystemProgram')) {
|
||||||
|
$program = app('SystemProgram');
|
||||||
|
} else {
|
||||||
|
if ($request->has('program_id') && $request->query('program_id')) {
|
||||||
|
$programId = $request->query('program_id');
|
||||||
|
$program = Program::find($programId);
|
||||||
|
if (!$program) {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$petani = PetaniCPM::findOrFail($id);
|
$petani = PetaniCPM::findOrFail($id);
|
||||||
|
|
||||||
$pendidikan = Pendidikan::options();
|
$pendidikan = Pendidikan::options();
|
||||||
@@ -128,7 +190,7 @@ class PetaniCPMController extends Controller
|
|||||||
$komoditas = Komoditas::all();
|
$komoditas = Komoditas::all();
|
||||||
|
|
||||||
return view('ekosistem.petani-cpm.edit', compact('petani', 'pendidikan', 'pekerjaan',
|
return view('ekosistem.petani-cpm.edit', compact('petani', 'pendidikan', 'pekerjaan',
|
||||||
'pernikahan', 'statusKeluarga', 'provinsi', 'komoditas'));
|
'pernikahan', 'statusKeluarga', 'provinsi', 'komoditas', 'program'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -140,6 +202,20 @@ class PetaniCPMController extends Controller
|
|||||||
abort(403);
|
abort(403);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (app()->has('SystemProgram')) {
|
||||||
|
$program = app('SystemProgram');
|
||||||
|
} else {
|
||||||
|
if ($request->has('program_id') && $request->query('program_id')) {
|
||||||
|
$programId = $request->query('program_id');
|
||||||
|
$program = Program::find($programId);
|
||||||
|
if (!$program) {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
abort(400, 'Program tidak ditemukan.');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$petani = PetaniCPM::findOrFail($id);
|
$petani = PetaniCPM::findOrFail($id);
|
||||||
|
|
||||||
$validatedData = $request->validate([
|
$validatedData = $request->validate([
|
||||||
|
|||||||
@@ -150,6 +150,7 @@ class ValueBasisDataController extends Controller
|
|||||||
abort(404, 'Data kolom tidak ditemukan untuk tabel ini.');
|
abort(404, 'Data kolom tidak ditemukan untuk tabel ini.');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
$program = null;
|
||||||
if (app()->has('SystemProgram')) {
|
if (app()->has('SystemProgram')) {
|
||||||
$program = app('SystemProgram');
|
$program = app('SystemProgram');
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
@@ -44,6 +44,7 @@ class PetaniCPM extends Model
|
|||||||
'created_by',
|
'created_by',
|
||||||
'updated_by',
|
'updated_by',
|
||||||
'deleted_by',
|
'deleted_by',
|
||||||
|
'program_id',
|
||||||
];
|
];
|
||||||
|
|
||||||
protected $casts = [
|
protected $casts = [
|
||||||
|
|||||||
@@ -36,6 +36,10 @@ return new class extends Migration
|
|||||||
Schema::table('ekosistem_basis_data_value', function (Blueprint $table) {
|
Schema::table('ekosistem_basis_data_value', function (Blueprint $table) {
|
||||||
$table->integer('value_relasi')->nullable();
|
$table->integer('value_relasi')->nullable();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Schema::table('ekosistem_petani_cpm', function (Blueprint $table) {
|
||||||
|
$table->foreignId('program_id')->nullable()->constrained('core_program')->nullOnDelete();
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form id="addNewPetaniForm" action="{{ route('petani-cpm.store') }}" method="POST" >
|
<form id="addNewPetaniForm" action="{{ route('petani-cpm.store', ['program_id' => $program->id]) }}" method="POST" >
|
||||||
@csrf
|
@csrf
|
||||||
|
|
||||||
@if ($errors->any())
|
@if ($errors->any())
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body">
|
<div class="card-body">
|
||||||
<form id="addNewPetaniForm" action="{{ route('petani-cpm.update', $petani->id) }}" method="POST" >
|
<form id="addNewPetaniForm" action="{{ route('petani-cpm.update', [$petani->id, 'program_id' => $program->id]) }}" method="POST" >
|
||||||
@csrf
|
@csrf
|
||||||
@method('PUT')
|
@method('PUT')
|
||||||
|
|
||||||
|
|||||||
@@ -71,7 +71,7 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="card-body border-bottom pt-4">
|
<div class="card-body border-bottom pt-4">
|
||||||
<form method="GET" action="{{ route('tabel.index') }}" class="d-flex justify-content-between align-items-center row gap-3 gap-md-0">
|
<form method="GET" action="{{ route('petani-cpm.index') }}" class="d-flex justify-content-between align-items-center row gap-3 gap-md-0">
|
||||||
<div class="col-md-auto">
|
<div class="col-md-auto">
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<label class="me-2 text-nowrap">Show</label>
|
<label class="me-2 text-nowrap">Show</label>
|
||||||
@@ -84,11 +84,26 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-md-auto d-flex gap-2">
|
<div class="col-md-auto d-flex gap-2">
|
||||||
|
@if (app()->has('SystemProgram'))
|
||||||
|
@else
|
||||||
|
<div class="col-md-auto">
|
||||||
|
<div class="d-flex align-items-center">
|
||||||
|
<label class="me-2 text-nowrap">Program</label>
|
||||||
|
<select name="program_id" class="form-select form-select-sm w-auto" onchange="this.form.submit()" id="select-program">
|
||||||
|
<option value="">Pilih Program</option>
|
||||||
|
@foreach($programList as $prog)
|
||||||
|
<option value="{{ $prog->id }}" {{ request('program_id') == $prog->id ? 'selected' : '' }}>{{ $prog->nama }}</option>
|
||||||
|
@endforeach
|
||||||
|
</select>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
<div class="input-group input-group-sm w-auto">
|
<div class="input-group input-group-sm w-auto">
|
||||||
<input type="text" name="search" class="form-control" placeholder="Cari Nama Petani..." value="{{ request('search') }}">
|
<input type="text" name="search" class="form-control" placeholder="Cari Nama Petani..." value="{{ request('search') }}">
|
||||||
<button type="submit" class="btn btn-outline-primary"><i class="ti tabler-search"></i></button>
|
<button type="submit" class="btn btn-outline-primary"><i class="ti tabler-search"></i></button>
|
||||||
</div>
|
</div>
|
||||||
<a href="{{ route('petani-cpm.create') }}" class="btn btn-sm btn-primary">
|
<a href="{{ route('petani-cpm.create', ['program_id' => request('program_id')]) }}" class="btn btn-sm btn-primary"
|
||||||
|
style="display: {{ request('program_id') ? 'flex' : 'none' }};">
|
||||||
<i class="ti tabler-plus me-1"></i> Tambah
|
<i class="ti tabler-plus me-1"></i> Tambah
|
||||||
</a>
|
</a>
|
||||||
</div>
|
</div>
|
||||||
@@ -117,7 +132,7 @@
|
|||||||
<td><span class="text-muted">{{ $p->desaKelurahan?->nama }}, {{ $p->desaKelurahan?->kecamatan?->nama }}, {{ $p->desaKelurahan?->kecamatan?->kabupatenKota?->nama }}, {{ $p->desaKelurahan?->kecamatan?->kabupatenKota?->provinsi?->nama }}</span></td>
|
<td><span class="text-muted">{{ $p->desaKelurahan?->nama }}, {{ $p->desaKelurahan?->kecamatan?->nama }}, {{ $p->desaKelurahan?->kecamatan?->kabupatenKota?->nama }}, {{ $p->desaKelurahan?->kecamatan?->kabupatenKota?->provinsi?->nama }}</span></td>
|
||||||
<td>
|
<td>
|
||||||
<div class="d-flex align-items-center">
|
<div class="d-flex align-items-center">
|
||||||
<a href="{{ route('petani-cpm.edit', $p->id) }}" class="btn btn-icon btn-text-secondary rounded-pill edit-record"><i class="ti tabler-edit ti-md"></i></a>
|
<a href="{{ route('petani-cpm.edit', [$p->id, 'program_id' => $p->program_id]) }}" class="btn btn-icon btn-text-secondary rounded-pill edit-record"><i class="ti tabler-edit ti-md"></i></a>
|
||||||
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-record" data-id="{{ $p->id }}" data-nama="{{ $p->nama }}"><i class="ti tabler-trash ti-md"></i></a>
|
<a href="javascript:;" class="btn btn-icon btn-text-secondary rounded-pill delete-record" data-id="{{ $p->id }}" data-nama="{{ $p->nama }}"><i class="ti tabler-trash ti-md"></i></a>
|
||||||
<a href="{{ route('petani-cpm.show', $p->id) }}" class="btn btn-icon btn-text-secondary rounded-pill view-record"><i class="ti tabler-eye ti-md"></i></a>
|
<a href="{{ route('petani-cpm.show', $p->id) }}" class="btn btn-icon btn-text-secondary rounded-pill view-record"><i class="ti tabler-eye ti-md"></i></a>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
Reference in New Issue
Block a user