diff --git a/app/Http/Controllers/Api/ProgamBantuanController.php b/app/Http/Controllers/Api/ProgamBantuanController.php new file mode 100644 index 000000000..df20ba811 --- /dev/null +++ b/app/Http/Controllers/Api/ProgamBantuanController.php @@ -0,0 +1,125 @@ +middleware('auth:api'); + } + + public function store(ProgramBantuanRequest $request) + { + try { + // Upload file zip temporary. + $file = $request->file('file'); + $file->storeAs('temp', $name = $file->getClientOriginalName()); + + // Temporary path file + $path = storage_path("app/temp/{$name}"); + $extract = storage_path('app/public/bantuan/'); + + // Ekstrak file + $zip = new ZipArchive(); + $zip->open($path); + $zip->extractTo($extract); + $zip->close(); + + (new SinkronBantuan()) + ->queue($extract . $csvName = Str::replaceLast('zip', 'csv', $name)); + } catch (\Exception $e) { + report($e); + return response()->json([ + "status" => "danger", + "message" => $e->getMessage(), + ]); + } + + // Hapus folder temp ketika sudah selesai + Storage::deleteDirectory('temp'); + // Hapus file excell temp ketika sudah selesai + Storage::disk('public')->delete('bantuan' . $csvName); + + return response()->json([ + "message" => "Data Bantuan Sedang di Sinkronkan", + "status" => "success" + ]); + } + + public function storePeserta(ProgramBantuanRequest $request) + { + try { + // Upload file zip temporary. + $file = $request->file('file'); + $file->storeAs('temp', $name = $file->getClientOriginalName()); + // Temporary path file + $path = storage_path("app/temp/{$name}"); + $extract = storage_path('app/public/bantuan/'); + // Ekstrak file + $zip = new ZipArchive(); + $zip->open($path); + $zip->extractTo($extract); + $zip->close(); + // Proses impor excell + (new SinkronPesertaBantuan()) + ->queue($extract . $csvName = Str::replaceLast('zip', 'csv', $name)); + } catch (\Exception $e) { + report($e); + return response()->json([ + "status" => "danger", + "message" => $e->getMessage(), + ]); + } + // Hapus folder temp ketika sudah selesai + Storage::deleteDirectory('temp'); + // Hapus file excell temp ketika sudah selesai + Storage::disk('public')->delete('bantuan/' . $csvName); + return response()->json([ + "status" => "success", + "message" => "Data Bantuan Sedang di Sinkronkan", + ]); + } +} diff --git a/app/Http/Controllers/Data/ProgramBantuanController.php b/app/Http/Controllers/Data/ProgramBantuanController.php index 04ea41ce9..f569cc18b 100755 --- a/app/Http/Controllers/Data/ProgramBantuanController.php +++ b/app/Http/Controllers/Data/ProgramBantuanController.php @@ -32,6 +32,7 @@ namespace App\Http\Controllers\Data; use App\Http\Controllers\Controller; +use App\Models\DataDesa; use App\Models\PesertaProgram; use App\Models\Program; use Illuminate\Http\Request; @@ -43,17 +44,16 @@ public function index() { $page_title = 'Program Bantuan'; $page_description = 'Daftar Program Bantuan'; + $list_desa = DataDesa::all(); - return view('data.program_bantuan.index', compact('page_title', 'page_description')); + return view('data.program_bantuan.index', compact('page_title', 'page_description', 'list_desa')); } - public function getaProgramBantuan() + public function getaProgramBantuan(Request $request) { - return DataTables::of(Program::all()) + return DataTables::of(Program::when(!empty($request->input('desa')), fn ($q) => $q->where('desa_id', $request->desa))->with('desa')) ->addColumn('aksi', function ($row) { $data['detail_url'] = route('data.program-bantuan.show', $row->id); - $data['edit_url'] = route('data.program-bantuan.edit', $row->id); - $data['delete_url'] = route('data.program-bantuan.destroy', $row->id); return view('forms.aksi', $data); }) diff --git a/app/Http/Requests/ProgramBantuanRequest.php b/app/Http/Requests/ProgramBantuanRequest.php new file mode 100644 index 000000000..d9631ce14 --- /dev/null +++ b/app/Http/Requests/ProgramBantuanRequest.php @@ -0,0 +1,61 @@ + 'file|mimes:zip|max:5120', + "desa_id" => ['required', 'string', new CekDesa()], + ]; + } +} diff --git a/app/Imports/SinkronBantuan.php b/app/Imports/SinkronBantuan.php new file mode 100644 index 000000000..d8202359e --- /dev/null +++ b/app/Imports/SinkronBantuan.php @@ -0,0 +1,77 @@ + $value['id'], + 'nama' => $value['nama'], + 'sasaran' => $value['sasaran'], + 'status' => $value['status'], + 'start_date' => $value['sdate'], + 'end_date' => $value['edate'], + 'description' => $value['ndesc'], + 'desa_id' => $value['kode_desa'] + ]; + + Program::updateOrCreate([ + 'desa_id' => $insert['desa_id'], + 'id' => $insert['id'] + ], $insert); + } + } +} diff --git a/app/Imports/SinkronPesertaBantuan.php b/app/Imports/SinkronPesertaBantuan.php new file mode 100644 index 000000000..531e69575 --- /dev/null +++ b/app/Imports/SinkronPesertaBantuan.php @@ -0,0 +1,115 @@ +exists()) { + Log::debug("Sinkronisasi Peserta Bantuan Gagal. Nomor NIK {$value['kartu_nik']} tidak terdaftar."); + DB::rollBack(); // rollback data yang sudah masuk karena ada data yang bermasalah + Storage::deleteDirectory('temp'); // Hapus folder temp ketika gagal + throw new Exception("Nomor NIK {$value['kartu_nik']} tidak terdaftar."); + } + } else { + // cek kk penduduk + if (!Penduduk::where('nik', $value['kartu_nik'])->whereHas('keluarga')->exists()) { + Log::debug("Sinkronisasi Peserta Bantuan Gagal. Nomor KK dari NIK {$value['kartu_nik']} tidak terdaftar."); + DB::rollBack(); // rollback data yang sudah masuk karena ada data yang bermasalah + Storage::deleteDirectory('temp'); // Hapus folder temp ketika gagal + throw new Exception("Nomor KK dari NIK {$value['kartu_nik']} tidak terdaftar."); + } + } + + $insert = [ + 'id' => $value['id'], + 'peserta' => $value['peserta'], + 'program_id' => $value['program_id'], + 'no_id_kartu' => $value['no_id_kartu'], + 'kartu_nik' => $value['kartu_nik'], + 'kartu_nama' => $value['kartu_nama'], + 'sasaran' => $value['sasaran'], + 'kartu_tempat_lahir' => $value['kartu_tempat_lahir'], + 'kartu_tanggal_lahir' => $value['kartu_tanggal_lahir'], + 'kartu_alamat' => $value['kartu_alamat'], + 'kartu_peserta' => $value['kartu_peserta'], + 'desa_id' => $value['kode_desa'], + ]; + + PesertaProgram::updateOrCreate([ + 'kartu_nik' => $insert['kartu_nik'], + 'program_id' => $insert['program_id'], + 'desa_id' => $insert['desa_id'] + ], $insert); + } + + DB::commit(); // commit data dan simpan ke dalam database + // Hapus folder temp ketika sudah selesai + Storage::deleteDirectory('temp'); + } +} diff --git a/app/Models/PesertaProgram.php b/app/Models/PesertaProgram.php index abb38472d..7f5bade88 100755 --- a/app/Models/PesertaProgram.php +++ b/app/Models/PesertaProgram.php @@ -48,6 +48,7 @@ class PesertaProgram extends Model 'kartu_tanggal_lahir', 'kartu_alamat', 'kartu_peserta', + 'desa_id' ]; public function penduduk() diff --git a/app/Models/Program.php b/app/Models/Program.php index 260b0ca15..d2ffc0540 100755 --- a/app/Models/Program.php +++ b/app/Models/Program.php @@ -38,15 +38,23 @@ class Program extends Model protected $table = 'das_program'; protected $fillable = [ + 'id', 'nama', 'sasaran', 'start_date', 'end_date', 'description', + 'desa_id', + 'status' ]; public function pesertas() { return $this->hasMany(PesertaProgram::class, 'program_id', 'id'); } + + public function desa() + { + return $this->hasOne(DataDesa::class, 'desa_id', 'desa_id'); + } } diff --git a/catatan_rilis.md b/catatan_rilis.md index 1c37bdcc7..5db51f2f8 100644 --- a/catatan_rilis.md +++ b/catatan_rilis.md @@ -9,6 +9,7 @@ Terima kasih pada [untuk diisi] yang terus berkontribusi. Terima kasih pula pada 1. [#302](https://github.com/OpenSID/OpenDK/issues/302) Pengaturan peta kecamatan yang sesuai perda setempat pada data kecamatan. 2. [#333](https://github.com/OpenSID/OpenDK/issues/333) Sinkronisasi Data Pembangunan OpenSID ke OpenDK. 3. [#384](https://github.com/OpenSID/OpenDK/issues/384) Sediakan ganti password saat selesai login jika menggunakan password masih default. +4. [#416](https://github.com/OpenSID/OpenDK/issues/416) Sinkronisasi Data Program Bantuan OpenSID ke OpenDK. #### Perbaikan BUG diff --git a/database/migrations/2022_04_20_105732_tambahkan_kolom_programbantuan.php b/database/migrations/2022_04_20_105732_tambahkan_kolom_programbantuan.php new file mode 100644 index 000000000..330601b75 --- /dev/null +++ b/database/migrations/2022_04_20_105732_tambahkan_kolom_programbantuan.php @@ -0,0 +1,63 @@ +Char('desa_id', 13)->after('sasaran')->nullable(); + $table->tinyInteger('status', false, 1)->after('sasaran')->nullable(); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('das_program', function (Blueprint $table) { + $table->dropColumn('desa_id'); + $table->dropColumn('status'); + }); + } +} diff --git a/database/migrations/2022_04_20_115358_alter_programbantuan.php b/database/migrations/2022_04_20_115358_alter_programbantuan.php new file mode 100644 index 000000000..db223692c --- /dev/null +++ b/database/migrations/2022_04_20_115358_alter_programbantuan.php @@ -0,0 +1,65 @@ +text('description')->nullable()->change(); + $table->integer('id')->nullable(false)->unsigned()->change(); + $table->dropPrimary('id'); + $table->unique(['id', 'desa_id']); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('das_program', function (Blueprint $table) { + $table->string('description', 200)->nullable()->change(); + $table->integer('id', true)->nullable(false)->change(); + }); + } +} diff --git a/database/migrations/2022_04_20_122309_add_kolom_daspesertabantuan.php b/database/migrations/2022_04_20_122309_add_kolom_daspesertabantuan.php new file mode 100644 index 000000000..f46a8668c --- /dev/null +++ b/database/migrations/2022_04_20_122309_add_kolom_daspesertabantuan.php @@ -0,0 +1,61 @@ +Char('desa_id', 13)->after('kartu_peserta')->nullable(false); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('das_peserta_program', function (Blueprint $table) { + $table->dropColumn('desa_id'); + }); + } +} diff --git a/resources/views/data/program_bantuan/index.blade.php b/resources/views/data/program_bantuan/index.blade.php index e7e131f72..3a2c09cbe 100755 --- a/resources/views/data/program_bantuan/index.blade.php +++ b/resources/views/data/program_bantuan/index.blade.php @@ -18,20 +18,31 @@ @include('partials.flash_message')
-
- -
+
+
+
+ + + + + + +
+
+
+ @@ -42,24 +53,36 @@ @endsection - +@include('partials.asset_select2') @include('partials.asset_datatables') @push('scripts') @include('forms.datatable-vertical') diff --git a/resources/views/data/program_bantuan/show.blade.php b/resources/views/data/program_bantuan/show.blade.php index 96d29c404..5e575e506 100755 --- a/resources/views/data/program_bantuan/show.blade.php +++ b/resources/views/data/program_bantuan/show.blade.php @@ -2,120 +2,107 @@ @section('content') -
-

- {{ $page_title ?? "Page Title" }} - {{ $page_description ?? '' }} -

- -
+
+

+ {{ $page_title ?? 'Page Title' }} + {{ $page_description ?? '' }} +

+ +
-
+
- @include('partials.flash_message') + @include('partials.flash_message') -
- -
-
-
Aksi Nama ProgramDesa Masa Berlaku Sasaran
- - - - - - - - - - - - - - - - -
Nama: {{ $program->nama }}
Sasaran: {{ $sasaran[$program->sasaran] }}
Periode Program: {{ $program->start_date }} - {{ $program->end_date }}
Keterangan: {{ $program->description }}
-
-
- Daftar Peserta Program -
- - @if($program->sasaran == 1) - - - - - - - - - +
+
+
+
- - - - - + + - - @else - - - - - - - + + - - - - - + + - - @endif - - @if(count($peserta) > 0) - @foreach($peserta as $row) - - - - - - - - - - + + - @endforeach +
NIKNamaTempat LahirTanggal LahirAlamatNama: {{ $program->nama }}
AksiNo. KKNo. Kartu PesertaKepala KeluargaAlamatIdentitas di Kartu PesertaSasaran: {{ $sasaran[$program->sasaran] }}
NIKNamaTempat LahirTanggal LahirAlamatPeriode Program: {{ $program->start_date }} - {{ $program->end_date }}
{{ $loop->iteration }}{{ $row->peserta }}{!! $row->kartu_peserta !!}{!! $row->penduduk->nama !!}{!! $row->penduduk->alamat !!}{!! $row->kartu_nik !!}{!! $row->kartu_nama!!}{!! $row->kartu_tempat_lahir!!}{!! $row->kartu_tanggal_lahir!!}{!! $row->kartu_alamat!!}Keterangan: {{ $program->description }}
+
+
+ Daftar Peserta Program +
+ + @if ($program->sasaran == 1) + + + + + + + + + + + + + + + + @else - - - - @endif - - + + + Aksi + No. KK + Kepala Keluarga + Identitas di Kartu Peserta + + + No. Kartu Peserta + NIK + Nama + Tempat Lahir + Tanggal Lahir + Alamat + + + @endif + + @if (count($peserta) > 0) + @foreach ($peserta as $row) + + {{ $loop->iteration }} + {{ $row->peserta }} + {!! $row->penduduk->nama !!} + {!! $row->no_id_kartu !!} + {!! $row->kartu_nik !!} + {!! $row->kartu_nama !!} + {!! $row->kartu_tempat_lahir !!} + {!! $row->kartu_tanggal_lahir !!} + {!! $row->kartu_alamat !!} + + @endforeach + @else + + Tidak ada peserta. + + @endif + + +
- - + @endsection - diff --git a/routes/api.php b/routes/api.php index 7fd3c63dc..4d2598e7e 100644 --- a/routes/api.php +++ b/routes/api.php @@ -100,4 +100,12 @@ Route::group(['prefix' => 'identitas-desa'], function () { Route::post('/', 'Api\ProfilDesaController@store'); }); + + /** + * Program Bantuan + */ + Route::group(['prefix' => 'program-bantuan'], function () { + Route::post('/', 'Api\ProgamBantuanController@store'); + Route::post('peserta', 'Api\ProgamBantuanController@storePeserta'); + }); });