diff --git a/.gitignore b/.gitignore
index 0f400e361..9b33a74ba 100644
--- a/.gitignore
+++ b/.gitignore
@@ -67,12 +67,17 @@ php.ini
# Ignore all files in Modules
Modules/*
+/assets/modules/*
# Do not ignore Anjungan folder and its contents
!Modules/Anjungan/
!Modules/Anjungan/**
!Modules/Analisis/
!Modules/Analisis/**
+!Modules/BukuTamu/
+!Modules/BukuTamu/**
+!Modules/Kehadiran/
+!Modules/Kehadiran/**
# Do not ignore specific files
!Modules/.gitkeep
diff --git a/Modules/Analisis/Enums/TahapPedataanEnum.php b/Modules/Analisis/Enums/TahapPedataanEnum.php
index 3f2fee362..20265f385 100644
--- a/Modules/Analisis/Enums/TahapPedataanEnum.php
+++ b/Modules/Analisis/Enums/TahapPedataanEnum.php
@@ -1,59 +1,561 @@
- 'Belum Entri / Pedataan',
- self::SEDANG_ENTRI => 'Sedang Dalam Pendataan',
- self::SELESAI_ENTRI => 'Selesai Entri / Pedataan',
- ];
- }
-}
+ 'Pilihan (Tunggal)',
- self::PILIHAN_GANDA => 'Pilihan (Ganda)',
- self::ISIAN_JUMLAH => 'Isian angka',
- self::ISIAN_TEKS => 'Isian Tulisan',
- ];
- }
-}
+segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master)
- {
- return view('analisis_indikator.index', [
- 'tipeKategori' => AnalisisKategori::where(['id_master' => $master])->pluck('kategori', 'id'),
- ]);
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $canUpdate = can('u');
- $canDelete = can('h');
- $orderColumn = $this->input->get('order')[0]['column'];
- $orderDesc = $this->input->get('order')[0]['dir'];
- $analisisMaster = $this->analisisMaster;
-
- return datatables()->of(AnalisisIndikator::with(['kategori'])->whereIdMaster($master)
- ->when($orderColumn == 3, static fn ($q) => $q->orderByRaw("LPAD(nomor, 10, ' ') {$orderDesc}")))
- ->addColumn('ceklist', static function ($row) {
- if (can('h')) {
- return '';
- }
- })
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($canUpdate, $canDelete, $analisisMaster): string {
- $aksi = '';
- if ($analisisMaster->isLock()) {
- return $aksi;
- }
- if ($canUpdate) {
- if (in_array($row->id_tipe, [TipePertanyaanEnum::PILIHAN_TUNGGAL, TipePertanyaanEnum::PILIHAN_GANDA])) {
- $aksi .= ' id}.parameter", $row->id) . '" class="btn bg-purple btn-sm" title="Jawaban">';
- }
- }
- $aksi .= ' id}.form", $row->id) . '" class="btn bg-orange btn-sm" title="Ubah Data">';
- if ($analisisMaster->jenis != TipePertanyaanEnum::PILIHAN_TUNGGAL && $canDelete) {
- $aksi .= ' id}.delete", $row->id) . '" class="btn bg-maroon btn-sm" title="Hapus Data" data-toggle="modal" data-target="#confirm-delete">';
- }
-
- return $aksi;
- })
- ->editColumn('act_analisis', static fn ($q) => StatusEnum::valueOf($q->act_analisis))
- ->editColumn('id_tipe', static fn ($q) => TipePertanyaanEnum::valueOf($q->id_tipe))
- ->rawColumns(['ceklist', 'aksi'])
- ->make();
- }
-
- return show_404();
- }
-
- public function form($master, $id = null)
- {
- isCan('u');
- $analisisMaster = $this->analisisMaster;
- $data['list_kategori'] = AnalisisKategori::where(['id_master' => $master])->pluck('kategori', 'id');
- $data['data_tabel'] = AnalisisIndikator::hubungan($analisisMaster->subjek_tipe);
- if ($id) {
- $data['action'] = 'Ubah';
- $data['form_action'] = ci_route('analisis_indikator.' . $master . '.update', $id);
- $data['analisis_indikator'] = AnalisisIndikator::findOrFail($id);
- $data['ubah'] = (AnalisisParameter::where('id_indikator', $id)->exists() && in_array($data['analisis_indikator']['id_tipe'], [1, 2])) ? false : true;
- } else {
- $data['action'] = 'Tambah';
- $data['form_action'] = ci_route('analisis_indikator.' . $master . '.insert');
- $data['analisis_indikator'] = null;
- $data['ubah'] = true;
- }
-
- return view('analisis_indikator.form', $data);
- }
-
- public function insert($master): void
- {
- isCan('u');
- $analisisMaster = $this->analisisMaster;
- if ($analisisMaster->isSystem()) {
- redirect_with('error', 'Analisis sistem tidak boleh dirubah', ci_route('analisis_indikator.' . $master));
- }
- $dataInsert = static::validate($this->request);
- $dataInsert['id_master'] = $master;
- if (AnalisisIndikator::create($dataInsert)) {
- redirect_with('success', 'Berhasil Tambah Data', ci_route('analisis_indikator.' . $master));
- }
- redirect_with('error', 'Gagal Tambah Data', ci_route('analisis_indikator.' . $master));
- }
-
- public function update($master, $id = null): void
- {
- isCan('u');
- $analisisMaster = $this->analisisMaster;
- $dataUpdate = static::validate($this->request, $id);
- if ($analisisMaster->isSystem()) {
- // Hanya kolom yang boleh diubah untuk analisis sistem
- $dataUpdate = ['is_publik' => $dataUpdate['is_publik']];
- }
- $data = AnalisisIndikator::findOrFail($id);
-
- if ($data->update($dataUpdate)) {
- redirect_with('success', 'Berhasil Ubah Data', ci_route('analisis_indikator.' . $master));
- }
- redirect_with('error', 'Gagal Ubah Data', ci_route('analisis_indikator.' . $master));
- }
-
- public function delete($master, $id = null): void
- {
- isCan('h');
- $analisisMaster = $this->analisisMaster;
- if ($analisisMaster->isSystem()) {
- redirect_with('error', 'Analisis sistem tidak boleh dihapus', ci_route('analisis_indikator.' . $master));
- }
- $adaParameter = AnalisisIndikator::whereIn('id', $id ? [$id] : $this->request['id_cb'])->whereHas('parameter')->exists();
- if ($adaParameter) {
- redirect_with('error', 'Gagal hapus, masih ada parameter dalam indikator tersebut', ci_route('analisis_indikator.' . $master));
- }
- if (AnalisisIndikator::destroy($id ?? $this->request['id_cb']) !== 0) {
- redirect_with('success', 'Berhasil Hapus Data', ci_route('analisis_indikator.' . $master));
- }
- redirect_with('error', 'Gagal Hapus Data', ci_route('analisis_indikator.' . $master));
- }
-
- protected static function validate(array $request = []): array
- {
- $data = [
- 'id_tipe' => $request['id_tipe'],
- 'referensi' => $request['referensi'] ?? null,
- 'nomor' => nomor_surat_keputusan($request['nomor']),
- 'pertanyaan' => htmlentities($request['pertanyaan']),
- 'id_kategori' => $request['id_kategori'] ?? null,
- 'bobot' => bilangan($request['bobot']),
- 'act_analisis' => $request['act_analisis'],
- 'is_publik' => $request['is_publik'],
- ];
-
- if ($data['id_tipe'] != 1) {
- $data['act_analisis'] = 2;
- $data['bobot'] = 0;
- }
-
- return $data;
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_kategori.php b/Modules/Analisis/Http/Controllers/Analisis_kategori.php
deleted file mode 100644
index 6216cb1df..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_kategori.php
+++ /dev/null
@@ -1,171 +0,0 @@
-segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master)
- {
- return view('analisis_kategori.index');
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $canUpdate = can('u');
- $canDelete = can('h');
- $analisisMaster = $this->analisisMaster;
-
- return datatables()->of(AnalisisKategori::whereIdMaster($master))
- ->addColumn('ceklist', static function ($row) {
- if (can('h')) {
- return '';
- }
- })
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($canUpdate, $canDelete, $analisisMaster): string {
- $aksi = '';
- if ($canUpdate) {
- $aksi .= 'id}.form", $row->id) . '" class="btn bg-orange btn-sm" title="Ubah Data" data-remote="false" data-toggle="modal" data-target="#modalBox" data-title="Ubah Data">';
- }
-
- if ($canDelete) {
- $aksi .= ' id}.delete", $row->id) . '" class="btn bg-maroon btn-sm" title="Hapus Data" data-toggle="modal" data-target="#confirm-delete">';
- }
-
- return $aksi;
- })
- ->rawColumns(['ceklist', 'aksi'])
- ->make();
- }
-
- return show_404();
- }
-
- public function form($master, $id = null)
- {
- isCan('u');
- if ($id) {
- $data['action'] = 'Ubah';
- $data['form_action'] = ci_route('analisis_kategori.' . $master . '.update', $id);
- $data['analisis_kategori'] = AnalisisKategori::findOrFail($id);
- } else {
- $data['action'] = 'Tambah';
- $data['form_action'] = ci_route('analisis_kategori.' . $master . '.insert');
- $data['analisis_kategori'] = null;
- }
-
- return view('analisis_kategori.form', $data);
- }
-
- public function insert($master): void
- {
- isCan('u');
- $dataInsert = static::validate($this->request);
- $dataInsert['id_master'] = $master;
- if (AnalisisKategori::create($dataInsert)) {
- redirect_with('success', 'Berhasil Tambah Data', ci_route('analisis_kategori.' . $master));
- }
- redirect_with('error', 'Gagal Tambah Data', ci_route('analisis_kategori.' . $master));
- }
-
- public function update($master, $id = null): void
- {
- isCan('u');
- $dataUpdate = static::validate($this->request, $id);
- $data = AnalisisKategori::findOrFail($id);
-
- if ($data->update($dataUpdate)) {
- redirect_with('success', 'Berhasil Ubah Data', ci_route('analisis_kategori.' . $master));
- }
- redirect_with('error', 'Gagal Ubah Data', ci_route('analisis_kategori.' . $master));
- }
-
- public function delete($master, $id = null): void
- {
- isCan('h');
- $ids = $id ? [$id] : $this->request['id_cb'];
-
- foreach ($ids as $id) {
- $this->prosesDelete($master, $id);
- }
- }
-
- private function prosesDelete($mater, $id = null): void
- {
- $cek = AnalisisKategori::withCount('indikator')->findOrFail($id);
-
- if ($cek->indikator_count > 0) {
- redirect_with('error', 'Gagal Hapus Data, Kategori masih digunakan', ci_route('analisis_kategori.' . $mater));
- }
-
- if ($cek->delete()) {
- redirect_with('success', 'Berhasil Hapus Data', ci_route('analisis_kategori.' . $mater));
- }
-
- redirect_with('error', 'Gagal Hapus Data', ci_route('analisis_kategori.' . $mater));
- }
-
- protected static function validate(array $request = []): array
- {
- return [
- 'kategori' => htmlentities($request['kategori']),
- ];
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_klasifikasi.php b/Modules/Analisis/Http/Controllers/Analisis_klasifikasi.php
deleted file mode 100644
index 7a0b43d48..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_klasifikasi.php
+++ /dev/null
@@ -1,157 +0,0 @@
-segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master)
- {
- return view('analisis_klasifikasi.index');
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $canUpdate = can('u');
- $canDelete = can('h');
-
- return datatables()->of(AnalisisKlasifikasi::whereIdMaster($master))
- ->addColumn('ceklist', static function ($row) {
- if (can('h')) {
- return '';
- }
- })
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($canUpdate, $canDelete, $master) {
- $aksi = '';
- if ($canUpdate) {
- $aksi .= 'id) . '" class="btn bg-orange btn-sm" title="Ubah Data" data-remote="false" data-toggle="modal" data-target="#modalBox" data-title="Ubah Data">';
- }
-
- if ($canDelete) {
- $aksi .= ' id) . '" class="btn bg-maroon btn-sm" title="Hapus Data" data-toggle="modal" data-target="#confirm-delete">';
- }
-
- return $aksi;
- })
- ->rawColumns(['ceklist', 'aksi'])
- ->make();
- }
-
- return show_404();
- }
-
- public function form($master, $id = null)
- {
- isCan('u');
- if ($id) {
- $data['action'] = 'Ubah';
- $data['form_action'] = ci_route('analisis_klasifikasi.' . $master . '.update', $id);
- $data['analisis_klasifikasi'] = AnalisisKlasifikasi::findOrFail($id);
- } else {
- $data['action'] = 'Tambah';
- $data['form_action'] = ci_route('analisis_klasifikasi.' . $master . '.insert');
- $data['analisis_klasifikasi'] = null;
- }
-
- return view('analisis_klasifikasi.form', $data);
- }
-
- public function insert($master): void
- {
- isCan('u');
- $dataInsert = static::validate($this->request);
- $dataInsert['id_master'] = $master;
- if (AnalisisKlasifikasi::create($dataInsert)) {
- redirect_with('success', 'Berhasil Tambah Data', ci_route('analisis_klasifikasi.' . $master));
- }
- redirect_with('error', 'Gagal Tambah Data', ci_route('analisis_klasifikasi.' . $master));
- }
-
- public function update($master, $id = null): void
- {
- isCan('u');
- $dataUpdate = static::validate($this->request, $id);
- $data = AnalisisKlasifikasi::findOrFail($id);
-
- if ($data->update($dataUpdate)) {
- redirect_with('success', 'Berhasil Ubah Data', ci_route('analisis_klasifikasi.' . $master));
- }
- redirect_with('error', 'Gagal Ubah Data', ci_route('analisis_klasifikasi.' . $master));
- }
-
- public function delete($master, $id = null): void
- {
- isCan('h');
-
- if (AnalisisKlasifikasi::destroy($id ?? $this->request['id_cb']) !== 0) {
- redirect_with('success', 'Berhasil Hapus Data', ci_route('analisis_klasifikasi.' . $master));
- }
- redirect_with('error', 'Gagal Hapus Data', ci_route('analisis_klasifikasi.' . $master));
- }
-
- protected static function validate(array $request = []): array
- {
- return [
- 'nama' => nomor_surat_keputusan($request['nama']),
- 'minval' => bilangan_titik($request['minval']),
- 'maxval' => bilangan_titik($request['maxval']),
- ];
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_laporan.php b/Modules/Analisis/Http/Controllers/Analisis_laporan.php
deleted file mode 100644
index 71c691b5f..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_laporan.php
+++ /dev/null
@@ -1,252 +0,0 @@
-segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- if ($master) {
- $this->periodeAktif = AnalisisPeriode::whereIdMaster($master)->where(['aktif' => StatusEnum::YA])->first();
- if (! $this->periodeAktif) {
- redirect_with('error', 'Tidak ada periode aktif. Untuk laporan ini harus ada periode aktif.', ci_route('analisis_periode', $master));
- }
- }
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master): void
- {
- $data = [
- 'judul' => Analisis::judul_subjek($this->analisisMaster->subjek_tipe),
- 'list_klasifikasi' => AnalisisKlasifikasi::where('id_master', $master)->get(),
- 'analisis_periode' => $this->periodeAktif->id,
- 'wilayah' => Wilayah::treeAccess(),
- 'namaPeriode' => $this->periodeAktif->nama,
- ];
-
- view('analisis_laporan.index', $data);
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $sumberData = $this->sumberData();
-
- return datatables()->of($sumberData)
- ->addIndexColumn()
- ->addColumn('aksi', static fn ($row): string => 'id) . '" class="btn bg-purple btn-sm" title="Input Data">')->editColumn('alamat', static fn ($q) => strtoupper($q->alamat . ' ' . 'RT/RW ' . $q->rt . '/' . $q->rw . ' - ' . setting('sebutan_dusun') . ' ' . $q->dusun))
- ->editColumn('nilai', static fn ($q) => $q->nilai ? number_format($q->nilai, 2, ',', '.') : '-')
- ->editColumn('sex', static fn ($q) => strtoupper(JenisKelaminEnum::valueOf($q->sex)))
- ->editColumn('cek', static fn ($q) => '')
- ->rawColumns(['ceklist', 'aksi', 'cek'])
- ->make();
- }
-
- return show_404();
- }
-
- private function sumberData()
- {
- $dusun = $this->input->get('dusun') ?? null;
- $rw = $this->input->get('rw') ?? null;
- $rt = $this->input->get('rt') ?? null;
- $klasifikasi = $this->input->get('klasifikasi') ?? null;
-
- $idCluster = $rt ? [$rt] : [];
-
- if (empty($idCluster) && ! empty($rw)) {
- [$namaDusun, $namaRw] = explode('__', $rw);
- $idCluster = Wilayah::whereDusun($namaDusun)->whereRw($namaRw)->select(['id'])->get()->pluck('id')->toArray();
- }
-
- if (empty($idCluster) && ! empty($dusun)) {
- $idCluster = Wilayah::whereDusun($dusun)->select(['id'])->get()->pluck('id')->toArray();
- }
-
- $analisisMaster = $this->analisisMaster;
- $analisSumberData = Analisis::sumberData($analisisMaster->subjek_tipe, $idCluster);
- $utama = $analisSumberData['utama'];
- $sumber = $analisSumberData['sumber'];
- $pembagi = (int) $analisisMaster->pembagi;
-
- $sumber->selectRaw("CAST((analisis_respon_hasil.akumulasi/{$pembagi}) AS decimal(8,3)) AS nilai, analisis_klasifikasi.nama AS klasifikasi")
- ->leftJoin('analisis_respon_hasil', $utama . '.id', '=', 'analisis_respon_hasil.id_subjek')
- ->leftJoin('analisis_klasifikasi', static function ($join) use ($pembagi, $analisisMaster) {
- $join->on(DB::raw("analisis_respon_hasil.akumulasi / {$pembagi}"), '>=', 'analisis_klasifikasi.minval')
- ->on(DB::raw("analisis_respon_hasil.akumulasi / {$pembagi}"), '<=', 'analisis_klasifikasi.maxval')
- ->on('analisis_klasifikasi.id_master', '=', DB::raw($analisisMaster->id));
- })
- ->where('analisis_respon_hasil.id_periode', $this->periodeAktif->id);
- if ($klasifikasi) {
- $sumber->where('analisis_klasifikasi.id', $klasifikasi);
- }
-
- return $sumber;
- }
-
- public function form($master, $idSubjek): void
- {
- $analisis = new Analisis();
-
- $data['total'] = AnalisisResponHasil::where(['id_subjek' => $idSubjek, 'id_periode' => $this->periodeAktif->id])->first()->akumulasi ?? 0;
- $data['subjek'] = $analisis->getSubjek($this->analisisMaster, $idSubjek) ?? show_404();
- $data['list_jawab'] = $analisis->listIndikatorLaporan($this->analisisMaster, $this->periodeAktif->id, $idSubjek);
- $data['list_bukti'] = $analisis->listBukti($this->analisisMaster, $this->periodeAktif->id, $idSubjek);
- $data['list_anggota'] = $analisis->listAnggota($this->analisisMaster, $idSubjek);
- $data['asubjek'] = $this->analisisMaster->subjek_tipe == AnalisisRefSubjekEnum::DESA ? ucwords(setting('sebutan_desa')) : AnalisisRefSubjekEnum::valueOf($this->analisisMaster->subjek_tipe);
- $data['id'] = $idSubjek;
-
- view('analisis_laporan.form', $data);
- }
-
- // $aksi = cetak/unduh
- public function dialog_kuisioner($master, $id, $aksi = ''): void
- {
- $data = $this->modal_penandatangan();
- $data['aksi'] = ucwords((string) $aksi);
- $data['form_action'] = ci_route("analisis_laporan.{$master}.daftar.{$id}.{$aksi}");
-
- view('admin.layouts.components.ttd_pamong', $data);
- }
-
- public function daftar($master, $idSubjek, $aksi = ''): void
- {
- $analisis = new Analisis();
- $data['total'] = AnalisisResponHasil::where(['id_subjek' => $idSubjek, 'id_periode' => $this->periodeAktif->id])->first()->akumulasi ?? 0;
- $data['subjek'] = $analisis->getSubjek($this->analisisMaster, $idSubjek) ?? show_404();
- $data['list_jawab'] = $analisis->listIndikatorLaporan($this->analisisMaster, $this->periodeAktif->id, $idSubjek);
- $data['list_bukti'] = $analisis->listBukti($this->analisisMaster, $this->periodeAktif->id, $idSubjek);
- $data['list_anggota'] = $analisis->listAnggota($this->analisisMaster, $idSubjek);
- $data['asubjek'] = $this->analisisMaster->subjek_tipe == AnalisisRefSubjekEnum::DESA ? ucwords(setting('sebutan_desa')) : AnalisisRefSubjekEnum::valueOf($this->analisisMaster->subjek_tipe);
-
- $data['config'] = $this->header['desa'];
- $data['pamong_ttd'] = Pamong::selectData()->where(['pamong_id' => $this->input->post('pamong_ttd')])->first()->toArray();
- $data['pamong_ketahui'] = Pamong::selectData()->where(['pamong_id' => $this->input->post('pamong_ketahui')])->first()->toArray();
- $data['aksi'] = $aksi;
-
- view('analisis_laporan.form_cetak', $data);
- }
-
- // $aksi = cetak/unduh
- public function dialog($master, $aksi = ''): void
- {
- // Simpan session lama
- $data = $this->modal_penandatangan();
- $data['aksi'] = ucwords((string) $aksi);
- $data['form_action'] = ci_route("analisis_laporan.{$master}.cetak.{$aksi}");
-
- view('analisis_laporan.ttd_pamong', $data);
- }
-
- public function cetak($master, $aksi = ''): void
- {
- $paramDatatable = json_decode((string) $this->input->post('params'), 1);
- $_GET = $paramDatatable;
-
- $query = $this->sumberData();
-
- $data['pamong_ttd'] = Pamong::selectData()->where(['pamong_id' => $this->input->post('pamong_ttd')])->first()->toArray();
- $data['pamong_ketahui'] = Pamong::selectData()->where(['pamong_id' => $this->input->post('pamong_ketahui')])->first()->toArray();
- $data['aksi'] = $aksi;
- $data['config'] = $this->header['desa'];
- // $data['judul'] = Analisis::judul_subjek($this->analisisMaster->subjek_tipe);
- $data['file'] = 'Laporan Hasil Analisis ' . AnalisisRefSubjekEnum::valueOf($this->analisisMaster->subjek_tipe);
- $data['isi'] = 'analisis_laporan.table_print';
- $data['main'] = $query->get();
- $data['letak_ttd'] = ['2', '2', '1'];
-
- view('admin.layouts.components.format_cetak', $data);
- }
-
- public function ajax_multi_jawab($master): void
- {
- $data['jawab'] = session('jawab') ?? '';
- $data['main'] = (new Analisis())->multi_jawab($master);
- $data['form_action'] = ci_route("analisis_laporan.{$master}.multi_jawab_proses");
-
- view('analisis_laporan.ajax_multi', $data);
- }
-
- public function multi_jawab_proses($master): void
- {
- if (isset($_POST['id_cb'])) {
- unset($_SESSION['jawab'], $_SESSION['jmkf']);
-
- $id_cb = $_POST['id_cb'];
- $cb = '';
- if (count($id_cb) > 0) {
- foreach ($id_cb as $id) {
- $cb .= $id . ',';
- }
- }
- set_session('jawab', $cb . '7777777');
- $jawab = session('jawab');
- set_session('jmkf', AnalisisParameter::selectRaw('DISTINCT(id_indikator) AS id_jmkf')->whereRaw('id in (' . $jawab . ')')->count());
- }
-
- redirect(ci_route("analisis_laporan.{$master}"));
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_master.php b/Modules/Analisis/Http/Controllers/Analisis_master.php
deleted file mode 100644
index 973496472..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_master.php
+++ /dev/null
@@ -1,470 +0,0 @@
-input->is_ajax_request()) {
- $canUpdate = can('u');
-
- return datatables()->of(AnalisisMaster::query())
- ->addColumn('ceklist', static function ($row) {
- if (can('h')) {
- return '';
- }
- })
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($canUpdate): string {
- $aksi = ' ';
- if ($canUpdate) {
- $aksi .= ' ';
- if ($row->gform_id) {
- $aksi .= ' ';
- }
- $aksi .= ' ';
-
- if ($row->jenis != 1 ) {
- $aksi .= ' ';
- }
- }
- $aksi .= ' ';
-
- return $aksi;
- })
- ->editColumn('subjek_tipe', static fn ($q) => AnalisisRefSubjekEnum::valueOf($q->subjek_tipe))
- ->editColumn('gform_last_sync', static fn ($q) => tgl_indo($q->gform_last_sync))
- ->rawColumns(['ceklist', 'aksi', 'gform_last_sync'])
- ->make();
- }
-
- return show_404();
- }
-
- public function form($id = null)
- {
- isCan('u');
- $data['list_format_impor'] = ['1' => 'BDT 2015'];
- $data['list_subjek'] = AnalisisRefSubjekEnum::all();
- $data['list_kelompok'] = KelompokMaster::get()->toArray();
- $data['list_analisis'] = AnalisisMaster::subjekPenduduk()->get()->toArray();
- if ($id) {
- $data['action'] = 'Ubah';
- $data['form_action'] = ci_route('analisis_master.update', $id);
- $data['analisis_master'] = AnalisisMaster::findOrFail($id);
- } else {
- $data['action'] = 'Tambah';
- $data['form_action'] = ci_route('analisis_master.insert');
- $data['analisis_master'] = null;
- }
-
- return view('analisis.form', $data);
- }
-
- public function insert(): void
- {
- isCan('u');
-
- if (AnalisisMaster::create(static::validate($this->request))) {
- redirect_with('success', 'Berhasil Tambah Data');
- }
- redirect_with('error', 'Gagal Tambah Data');
- }
-
- public function update($id = null): void
- {
- isCan('u');
-
- $data = AnalisisMaster::findOrFail($id);
-
- if ($data->update(static::validate($this->request, $id))) {
- redirect_with('success', 'Berhasil Ubah Data');
- }
- redirect_with('error', 'Gagal Ubah Data');
- }
-
- public function delete($id = null): void
- {
- isCan('h');
-
- if (AnalisisMaster::destroy($id ?? $this->request['id_cb']) !== 0) {
- redirect_with('success', 'Berhasil Hapus Data');
- }
- redirect_with('error', 'Gagal Hapus Data');
- }
-
- public function import_analisis(): void
- {
- isCan('u');
-
- view('analisis.import', [
- 'form_action' => ci_route('analisis_master.import'),
- 'formatImpor' => ci_route('unduh', encrypt(DEFAULT_LOKASI_IMPOR . 'analisis.xlsx')),
- 'formatPpls2' => ci_route('unduh', encrypt(DEFAULT_LOKASI_IMPOR . 'ppls2.xlsx')),
- ]);
- }
-
- public function import(): void
- {
- isCan('u');
- $config['upload_path'] = sys_get_temp_dir();
- $config['allowed_types'] = 'xlsx';
-
- $namaFile = $config['upload_path'] . DIRECTORY_SEPARATOR . $this->upload('userfile', $config);
-
- try {
- (new Import($namaFile))->analisis();
- redirect_with('success', 'Berhasil import analisis');
- } catch (Exception $e) {
- redirect_with('error', 'Gagal import analisis ' . $e->getMessage());
- }
-
- }
-
- public function ekspor($id): void
- {
- $writer = new Writer();
- $master = AnalisisMaster::find($id) ?? show_404();
- $master = $master->toArray();
- //Nama File
- $tgl = date('Y_m_d');
- $fileName = 'analisis_' . urlencode((string) $master['nama']) . '_' . $tgl . '.xlsx';
- $writer->openToBrowser($fileName); // stream data directly to the browser
-
- $this->ekspor_master($writer, $master);
- $this->ekspor_pertanyaan($writer, $master);
- $this->ekspor_jawaban($writer, $master);
- $this->ekspor_klasifikasi($writer, $master);
-
- $writer->close();
-
- redirect('analisis_master');
- }
-
- private function style_judul(): Style
- {
- $border = new Border(
- new BorderPart(Border::TOP, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID),
- new BorderPart(Border::BOTTOM, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID),
- new BorderPart(Border::LEFT, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID),
- new BorderPart(Border::RIGHT, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID)
- );
-
- return (new Style())
- ->setFontBold()
- ->setFontSize(14)
- ->setBorder($border);
- }
-
- private function style_baris(): Style
- {
- $border = new Border(
- new BorderPart(Border::TOP, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID),
- new BorderPart(Border::BOTTOM, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID),
- new BorderPart(Border::LEFT, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID),
- new BorderPart(Border::RIGHT, Color::GREEN, Border::WIDTH_THIN, Border::STYLE_SOLID)
- );
-
- return (new Style())
- ->setBorder($border);
- }
-
- private function ekspor_master(Writer $writer, array $master): void
- {
- $sheet = $writer->getCurrentSheet();
- $sheet->setName('master');
- $periode = AnalisisPeriode::active()->where('id_master', $master['id'])->first();
- //Tulis judul
- $master_analisis = [
- ['NAMA ANALISIS', $master['nama']],
- ['SUBJEK', $master['subjek_tipe']],
- ['STATUS', $master['lock']],
- ['BILANGAN PEMBAGI', $master['pembagi']],
- ['DESKRIPSI ANALISIS', $master['deskripsi']],
- ['NAMA PERIODE', $periode->nama ?? ''],
- ['TAHUN PENDATAAN', $periode->tahun_pelaksanaan ?? ''],
- ];
-
- foreach ($master_analisis as $baris_master) {
- $baris = [
- $baris_master[0],
- $baris_master[1],
- ];
- $row = Row::fromValues($baris);
- $writer->addRow($row);
- }
- }
-
- private function ekspor_pertanyaan(Writer $writer, array $master): void
- {
- $sheet = $writer->addNewSheetAndMakeItCurrent();
- $sheet->setName('pertanyaan');
- //Tulis judul
- $daftar_kolom = [
- ['NO / KODE', 'nomor'],
- ['PERTANYAAN / INDIKATOR', 'pertanyaan'],
- ['KATEGORI / ASPEK', 'kategori'],
- ['TIPE PERTANYAAN', 'id_tipe'],
- ['BOBOT', 'bobot'],
- ['AKSI ANALISIS', 'act_analisis'],
- ];
- $judul = array_column($daftar_kolom, 0);
- $header = Row::fromValues($judul, $this->style_judul());
- $writer->addRow($header);
- // Tulis data
- $indikator = AnalisisIndikator::with(['kategori'])->where(['id_master' => $master['id']])->get()->toArray();
-
- foreach ($indikator as $p) {
- $baris_data = [$p['nomor'], $p['pertanyaan'], $p['kategori']['kategori'] ?? '', $p['id_tipe'], $p['bobot'], $p['act_analisis']];
- $baris = Row::fromValues($baris_data, $this->style_baris());
- $writer->addRow($baris);
- }
- }
-
- private function ekspor_jawaban(Writer $writer, array $master): void
- {
- $jawaban = $writer->addNewSheetAndMakeItCurrent();
- $jawaban->setName('jawaban');
- //Tulis judul
- $daftar_kolom = [
- ['KODE PERTANYAAN', 'nomor'],
- ['KODE JAWABAN', 'kode_jawaban'],
- ['ISI JAWABAN', 'jawaban'],
- ['NILAI', 'nilai'],
- ];
- $judul = array_column($daftar_kolom, 0);
- $header = Row::fromValues($judul, $this->style_judul());
- $writer->addRow($header);
- // Tulis data
- $parameter = AnalisisIndikator::with(['parameter'])->where(['id_master' => $master['id']])->get();
-
- foreach ($parameter as $p) {
- $baris_data = [$p['nomor'], $p['parameter']['kode_jawaban'] ?? '', $p['parameter']['jawaban'] ?? '', $p['parameter']['nilai'] ?? ''];
- $baris = Row::fromValues($baris_data, $this->style_baris());
- $writer->addRow($baris);
- }
- }
-
- private function ekspor_klasifikasi(Writer $writer, array $master): void
- {
- $klasifikasi = $writer->addNewSheetAndMakeItCurrent();
- $klasifikasi->setName('klasifikasi');
- //Tulis judul
- $daftar_kolom = [
- ['KLASIFIKASI', 'nama'],
- ['NILAI MINIMAL', 'minval'],
- ['NILAI MAKSIMAL', 'maxval'],
- ];
- $judul = array_column($daftar_kolom, 0);
- $header = Row::fromValues($judul, $this->style_judul());
- $writer->addRow($header);
- // Tulis data
- $klasifikasi = AnalisisKlasifikasi::where(['id_master' => $master['id']])->get();
-
- foreach ($klasifikasi as $k) {
- $baris_data = [$k['nama'], $k['minval'], $k['maxval']];
- $baris = Row::fromValues($baris_data, $this->style_baris());
- $writer->addRow($baris);
- }
- }
-
- public function import_gform(): void
- {
- isCan('u');
- $data['form_action'] = ci_route('analisis_master.exec_import_gform');
-
- view('analisis.import_gform', $data);
- }
-
- /**
- * 1. Credential
- * 2. Id script
- * 3. Redirect URI
- *
- * - Jika 1 dan 2 diisi (asumsi user pakai akun google sendiri) eksekusi dari nilai yg diisi user. Abaikan isisan 3. Redirect ambil dari isian 1
- * - Jika 1 dan 2 kosong. 3 diisi. Import gform langsung menuju redirect field 3
- * - Jika semua tidak terisi (asumsi opensid ini yang jalan di server OpenDesa) ambil credential setting di file config
- */
- private function get_redirect_uri()
- {
- $api_gform_credential = setting('api_gform_credential') ?? config_item('api_gform_credential');
- if ($api_gform_credential) {
- $credential_data = json_decode(str_replace('\"', '"', $api_gform_credential), true);
- $redirect_uri = $credential_data['web']['redirect_uris'][0];
- }
- if (empty($redirect_uri)) {
- return setting('api_gform_redirect_uri');
- }
-
- return $redirect_uri;
- }
-
- public function exec_import_gform(): void
- {
- isCan('u');
- $this->session->google_form_id = $this->request->get('input-form-id');
-
- $REDIRECT_URI = $this->get_redirect_uri();
- $protocol = (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
- $self_link = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
-
- if ($this->request->get('outsideRetry') == 'true') {
- $url = $REDIRECT_URI . '?formId=' . $this->request->get('formId') . '&redirectLink=' . $self_link . '&outsideRetry=true&code=' . $this->input->get('code');
-
- $client = new Google\Client();
- $httpClient = $client->authorize();
- $response = $httpClient->get($url);
-
- $variabel = json_decode((string) $response->getBody(), true);
- set_session('data_import', $variabel);
- set_session('gform_id', $this->request->get('formId'));
- set_session('success', 5);
-
- redirect('analisis_master');
- } else {
- $url = $REDIRECT_URI . '?formId=' . $this->request->get('input-form-id') . '&redirectLink=' . $self_link;
- header('Location: ' . $url);
- }
- }
-
- public function save_import_gform(): void
- {
- isCan('u');
-
- try {
- (new Gform($this->request))->save();
- } catch (Exception $e) {
- redirect_with('error', $e->getMessage());
- }
-
- redirect('analisis_master');
- }
-
- public function update_gform($id = 0): void
- {
- isCan('u');
- $form_id = AnalisisMaster::find($id)?->gform_id;
-
- $REDIRECT_URI = $this->get_redirect_uri();
- $protocol = (! empty($_SERVER['HTTPS']) && $_SERVER['HTTPS'] !== 'off' || $_SERVER['SERVER_PORT'] == 443) ? 'https://' : 'http://';
- $self_link = $protocol . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
-
- if ($this->input->get('outsideRetry') == 'true') {
- $url = $REDIRECT_URI . '?formId=' . $this->input->get('formId') . '&redirectLink=' . $self_link . '&outsideRetry=true&code=' . $this->input->get('code');
-
- $client = new Google\Client();
- $httpClient = $client->authorize();
- $response = $httpClient->get($url);
-
- $variabel = json_decode((string) $response->getBody(), true);
- (new Gform($this->request))->update($id, $variabel);
-
- redirect('analisis_master');
- } else {
- $url = $REDIRECT_URI . '?formId=' . $this->session->google_form_id . '&redirectLink=' . $self_link;
- header('Location: ' . $url);
- }
- }
-
- public function lock($id): void
- {
- isCan('u');
- if (AnalisisMaster::gantiStatus($id, 'lock')) {
- redirect_with('success', 'Berhasil ubah status analisis');
- }
-
- redirect_with('error', 'Gagal status analisis');
- }
-
- public function menu($master)
- {
- $data = [
- 'analisis_master' => AnalisisMaster::findOrFail($master),
- ];
-
- return view('analisis.menu_default', $data);
- }
-
- protected static function validate(array $request = []): array
- {
- return [
- 'nama' => judul($request['nama']),
- 'subjek_tipe' => $request['subjek_tipe'],
- 'id_kelompok' => $request['id_kelompok'] ?: null,
- 'lock' => $request['lock'] ?: null,
- 'format_impor' => $request['format_impor'] ?: null,
- 'pembagi' => bilangan_titik($request['pembagi']),
- 'id_child' => $request['id_child'] ?: null,
- 'deskripsi' => htmlentities($request['deskripsi']),
- ];
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_parameter.php b/Modules/Analisis/Http/Controllers/Analisis_parameter.php
deleted file mode 100644
index 45cc26bb0..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_parameter.php
+++ /dev/null
@@ -1,175 +0,0 @@
- AnalisisMaster::findOrFail($master),
- 'selectedMenu' => $this->selectedMenu,
- 'baseRoute' => ci_route('analisis_indikator.' . $master . '.parameter.' . $indikator),
- ];
-
- return view('analisis_parameter.index', $data);
- }
-
- public function datatables($master, $indikator)
- {
- if ($this->input->is_ajax_request()) {
- $canUpdate = can('u');
- $analisisMaster = AnalisisMaster::find($master);
- $analisisIndikator = AnalisisIndikator::findOrFail($indikator);
-
- return datatables()->of(AnalisisParameter::whereIdIndikator($indikator))
- ->addColumn('ceklist', static function ($row) {
- if (can('h')) {
- return '';
- }
- })
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($canUpdate, $analisisMaster, $analisisIndikator): string {
- $aksi = '';
- if ($canUpdate) {
- $aksi .= 'id}.parameter.{$row->id_indikator}.form", $row->id) . '" class="btn bg-orange btn-sm" title="Ubah Data" data-remote="false" data-toggle="modal" data-target="#modalBox" data-title="Ubah Data Parameter">';
- }
-
- if ($analisisMaster->jenis != 1 && ! $analisisIndikator->referensi) {
- $aksi .= ' id}.parameter.{$row->id_indikator}.delete", $row->id) . '" class="btn bg-maroon btn-sm" title="Hapus Data" data-toggle="modal" data-target="#confirm-delete">';
- }
-
- return $aksi;
- })
- ->rawColumns(['ceklist', 'aksi'])
- ->make();
- }
-
- return show_404();
- }
-
- public function form($master, $indikator, $id = null)
- {
- isCan('u');
- $analisisMaster = AnalisisMaster::find($master);
- $data['selectedMenu'] = $this->selectedMenu;
- $data['analisis_master'] = $analisisMaster;
- $data['analisis_indikator'] = AnalisisIndikator::findOrFail($indikator);
- $data['analisis_parameter'] = null;
- if ($id) {
- $data['action'] = 'Ubah';
- $data['form_action'] = ci_route('analisis_indikator.' . $master . '.parameter.' . $indikator . '.update', $id);
- $data['analisis_parameter'] = AnalisisParameter::findOrFail($id);
- } else {
- $data['action'] = 'Tambah';
- $data['form_action'] = ci_route('analisis_indikator.' . $master . '.parameter.' . $indikator . '.insert');
- }
-
- return view('analisis_parameter.form', $data);
- }
-
- public function insert($master, $indikator): void
- {
- isCan('u');
- $analisisMaster = AnalisisMaster::findOrFail($master);
- if ($analisisMaster->isSystem()) {
- redirect_with('error', 'Analisis sistem tidak boleh dirubah', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
- $dataInsert = static::validate($this->request);
- $dataInsert['id_indikator'] = $indikator;
- if (AnalisisParameter::create($dataInsert)) {
- redirect_with('success', 'Berhasil Tambah Data', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
- redirect_with('error', 'Gagal Tambah Data', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
-
- public function update($master, $indikator, $id = null): void
- {
- isCan('u');
- $analisisMaster = AnalisisMaster::findOrFail($master);
- $dataUpdate = static::validate($this->request, $id);
- if ($analisisMaster->isSystem() || $this->request->referensi) {
- unset($dataUpdate['kode_jawaban'], $dataUpdate['jawaban']);
- }
- $data = AnalisisParameter::findOrFail($id);
-
- if ($data->update($dataUpdate)) {
- redirect_with('success', 'Berhasil Ubah Data', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
- redirect_with('error', 'Gagal Ubah Data', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
-
- public function delete($master, $indikator, $id = null): void
- {
- isCan('h');
- $analisisMaster = AnalisisMaster::findOrFail($master);
- if ($analisisMaster->isSystem()) {
- redirect_with('error', 'Analisis sistem tidak boleh dihapus', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
- if (AnalisisParameter::destroy($id ?? $this->request['id_cb']) !== 0) {
- redirect_with('success', 'Berhasil Hapus Data', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
- redirect_with('error', 'Gagal Hapus Data', ci_route('analisis_indikator.' . $master . '.parameter', $indikator));
- }
-
- protected static function validate(array $request = []): array
- {
- return [
- 'kode_jawaban' => bilangan($request['kode_jawaban']),
- 'jawaban' => htmlentities($request['jawaban']),
- 'nilai' => bilangan($request['nilai']),
- ];
-
- return $data;
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_periode.php b/Modules/Analisis/Http/Controllers/Analisis_periode.php
deleted file mode 100644
index f69c5a998..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_periode.php
+++ /dev/null
@@ -1,213 +0,0 @@
-segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master)
- {
- return view('analisis_periode.index');
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $canUpdate = can('u');
- $canDelete = can('h');
-
- return datatables()->of(AnalisisPeriode::whereIdMaster($master))
- ->addColumn('ceklist', static function ($row) use ($canDelete) {
- if ($canDelete) {
- return '';
- }
- })
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($canUpdate, $canDelete, $master): string {
- $aksi = '';
- if ($canUpdate) {
- $aksi .= 'id) . '" class="btn bg-orange btn-sm" title="Ubah Data" data-remote="false" data-toggle="modal" data-target="#modalBox" data-title="Ubah Data"> ';
-
- if ($row->isLock()) {
- $aksi .= 'id) . '" class="btn bg-navy btn-sm" title="Nonaktikan"> ';
- } else {
- $aksi .= 'id) . '" class="btn bg-navy btn-sm" title="Aktifkan"> ';
- }
- }
-
- if ($canDelete) {
- $aksi .= ' id) . '" class="btn bg-maroon btn-sm" title="Hapus Data" data-toggle="modal" data-target="#confirm-delete"> ';
- }
-
- return $aksi;
- })
- ->rawColumns(['ceklist', 'aksi'])
- ->make();
- }
-
- return show_404();
- }
-
- public function form($master, $id = null)
- {
- isCan('u');
- $data['tahapan'] = TahapPedataanEnum::all();
- if ($id) {
- $data['action'] = 'Ubah';
- $data['form_action'] = ci_route('analisis_periode.' . $master . '.update', $id);
- $data['analisis_periode'] = AnalisisPeriode::findOrFail($id);
- } else {
- $data['action'] = 'Tambah';
- $data['form_action'] = ci_route('analisis_periode.' . $master . '.insert');
- $data['analisis_periode'] = null;
- }
-
- return view('analisis_periode.form', $data);
- }
-
- public function insert($master): void
- {
- isCan('u');
- $dataInsert = static::validate($this->request);
- $dataInsert['id_master'] = $master;
- if ($result = AnalisisPeriode::create($dataInsert)) {
- if ($this->request['duplikasi']) {
- $this->duplikasi($master, $result->id, $this->request);
- }
-
- redirect_with('success', 'Berhasil Tambah Data', ci_route('analisis_periode.' . $master));
- }
- redirect_with('error', 'Gagal Tambah Data', ci_route('analisis_periode.' . $master));
- }
-
- public function update($master, $id = null): void
- {
- isCan('u');
- $dataUpdate = static::validate($this->request, $id);
- $data = AnalisisPeriode::findOrFail($id);
-
- if ($data->update($dataUpdate)) {
- redirect_with('success', 'Berhasil Ubah Data', ci_route('analisis_periode.' . $master));
- }
- redirect_with('error', 'Gagal Ubah Data', ci_route('analisis_periode.' . $master));
- }
-
- public function lock($master, $id = null): void
- {
- isCan('u');
-
- if (AnalisisPeriode::gantiStatus($id, 'aktif')) {
- redirect_with('success', 'Berhasil Ubah Data', ci_route('analisis_periode.' . $master));
- }
-
- redirect_with('error', 'Gagal Ubah Data', ci_route('analisis_periode.' . $master));
- }
-
- public function delete($master, $id = null): void
- {
- isCan('h');
-
- if (AnalisisPeriode::destroy($id ?? $this->request['id_cb']) !== 0) {
- redirect_with('success', 'Berhasil Hapus Data', ci_route('analisis_periode.' . $master));
- }
- redirect_with('error', 'Gagal Hapus Data', ci_route('analisis_periode.' . $master));
- }
-
- protected static function validate(array $request = []): array
- {
- return [
- 'nama' => htmlentities($request['nama']),
- 'id_state' => bilangan($request['id_state']),
- 'aktif' => bilangan($request['aktif']),
- 'keterangan' => htmlentities($request['keterangan']),
- 'tahun_pelaksanaan' => bilangan($request['tahun_pelaksanaan']),
- ];
- }
-
- private function duplikasi($idMaster, $idPeriode, $request): void
- {
- // Jika status aktif, maka nonaktifkan semua periode yang aktif lainnya pada master yang sama
- if ($request['aktif'] == 1) {
- AnalisisPeriode::where('id_master', $idMaster)->where('id', '!=', $idPeriode)->update(['aktif' => 0]);
- }
-
- if ($request['duplikasi'] == 1) {
- $dpd = AnalisisPeriode::where('id_master', $idMaster)
- ->where('id', '!=', $idPeriode)
- ->orderBy('id', 'desc')
- ->first();
- $sblm = $dpd->id;
- $skrg = $idPeriode;
-
- $dataRespon = AnalisisRespon::where('id_periode', $sblm)
- ->get(['id_subjek', 'id_indikator', 'id_parameter']);
-
- if ($dataRespon->isNotEmpty()) {
- $dataRespon->each(static function ($item) use ($skrg) {
- $item->id_periode = $skrg;
- });
-
- AnalisisRespon::insert($dataRespon->toArray());
- AnalisisResponHasil::preUpdate($idMaster, $skrg);
- }
- }
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_respon.php b/Modules/Analisis/Http/Controllers/Analisis_respon.php
deleted file mode 100644
index 6897a1c28..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_respon.php
+++ /dev/null
@@ -1,312 +0,0 @@
-segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- if ($master) {
- $this->periodeAktif = AnalisisPeriode::whereIdMaster($master)->where(['aktif' => StatusEnum::YA])->first();
- if (! $this->periodeAktif) {
- redirect_with('error', 'Tidak ada periode aktif. Entri data respon harus ada periode aktif.', ci_route('analisis_periode', $master));
- }
- }
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master)
- {
- $data = array_merge([
- 'wilayah' => Wilayah::treeAccess(),
- 'namaPeriode' => $this->periodeAktif->nama,
- ], Analisis::judul_subjek($this->analisisMaster->subjek_tipe));
-
- return view('analisis_respon.index', $data);
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $sumberData = $this->sumberData();
-
- return datatables()->of($sumberData)
- ->addIndexColumn()
- ->addColumn('aksi', static function ($row) use ($master): string {
- $aksi = '';
- if (can('u')) {
- $aksi .= 'id) . '" class="btn bg-purple btn-sm" title="Input Data">';
- }
- if ($row->bukti_pengesahan) {
- $aksi .= ' ';
- }
-
- return $aksi;
- })->editColumn('cek', static fn ($q) => '')
- ->rawColumns(['ceklist', 'aksi', 'cek'])
- ->make();
- }
-
- return show_404();
- }
-
- private function sumberData()
- {
- $dusun = $this->input->get('dusun') ?? null;
- $rw = $this->input->get('rw') ?? null;
- $rt = $this->input->get('rt') ?? null;
- $isi = $this->input->get('isi') ?? null;
-
- $idCluster = $rt ? [$rt] : [];
-
- if (empty($idCluster) && ! empty($rw)) {
- [$namaDusun, $namaRw] = explode('__', $rw);
- $idCluster = Wilayah::whereDusun($namaDusun)->whereRw($namaRw)->select(['id'])->get()->pluck('id')->toArray();
- }
-
- if (empty($idCluster) && ! empty($dusun)) {
- $idCluster = Wilayah::whereDusun($dusun)->select(['id'])->get()->pluck('id')->toArray();
- }
-
- $analisisMaster = $this->analisisMaster;
- $analisSumberData = Analisis::sumberData($analisisMaster->subjek_tipe, $idCluster);
- $utama = $analisSumberData['utama'];
- $sumber = $analisSumberData['sumber'];
-
- $sumber->selectRaw('(SELECT a.id_subjek FROM analisis_respon a WHERE a.id_subjek = ' . $utama . ".id AND a.id_periode = {$this->periodeAktif->id} LIMIT 1) as cek")
- ->selectRaw("(SELECT b.pengesahan FROM analisis_respon_bukti b WHERE b.id_master = {$analisisMaster->id} AND b.id_periode = {$this->periodeAktif->id} AND b.id_subjek = " . $utama . '.id limit 1) as bukti_pengesahan');
-
- if ($isi) {
- switch($isi) {
- case 1:
- $sumber->whereRaw("(SELECT COUNT(id_subjek) FROM analisis_respon_hasil WHERE id_subjek = {$utama}.id AND id_periode = {$this->periodeAktif->id}) > 0");
- break;
-
- case 2:
- $sumber->whereRaw("(SELECT COUNT(id_subjek) FROM analisis_respon_hasil WHERE id_subjek = {$utama}.id AND id_periode = {$this->periodeAktif->id}) = 0");
- break;
- }
- }
-
- return $sumber;
- }
-
- public function form($master, $idSubjek)
- {
- isCan('u');
- $analisis = new Analisis();
- $data['fullscreen'] = $this->input->get('fs') ?? null;
- $data['form_action'] = ci_route('analisis_respon.' . $master . '.update', $idSubjek);
- $data['idSubjek'] = $idSubjek;
-
- $data['subjek'] = $analisis->getSubjek($this->analisisMaster, $idSubjek) ?? show_404();
- $data['list_jawab'] = $analisis->listIndikator($this->analisisMaster, $this->periodeAktif->id, $idSubjek);
- $data['list_bukti'] = $analisis->listBukti($this->analisisMaster, $this->periodeAktif->id, $idSubjek);
- $data['list_anggota'] = $analisis->listAnggota($this->analisisMaster, $idSubjek);
- $data['perbaharui'] = ci_route('analisis_respon.' . $master . '.perbaharui', $idSubjek);
-
- return view('analisis_respon.form', $data);
- }
-
- public function update($master, $idSubjek): void
- {
- isCan('u');
- DB::beginTransaction();
-
- try {
- if (! empty($_FILES['pengesahan']['name'])) {
- $per = $this->periodeAktif->id;
- $namaFile = implode('_', [$master, $per, $idSubjek, random_int(10000, 99999)]) . '.jpg';
- $config['upload_path'] = LOKASI_PENGESAHAN;
- $config['allowed_types'] = 'jpg|jpeg';
- $config['max_size'] = 1024;
- $config['file_name'] = $namaFile;
-
- $namaFile = $this->upload('pengesahan', $config, ci_route('analisis_respon.' . $master . '.form', $idSubjek));
- $bukti['pengesahan'] = $namaFile;
- $bukti['id_master'] = $master;
- $bukti['id_subjek'] = $idSubjek;
- $bukti['id_periode'] = $per;
- $bukti = AnalisisResponBukti::firstOrCreate($bukti);
- $bukti->pengesahan = $namaFile;
- $bukti->save();
- }
- AnalisisRespon::updateKuisioner($master, $this->periodeAktif->id, $_POST, $idSubjek);
- DB::commit();
- redirect_with('success', 'Berhasil Simpan Data Kuisioner', ci_route('analisis_respon.' . $master . '.form', $idSubjek));
- } catch (Exception $e) {
- DB::rollBack();
- log_message('error', $e->getMessage());
- redirect_with('error', 'Gagal Ubah Data Kuisioner ' . $e->getMessage(), ci_route('analisis_respon.' . $master . '.form', $idSubjek));
- }
- }
-
- public function perbaharui($master, $idSubjek): void
- {
- isCan('u');
- AnalisisRespon::where('id_subjek', $idSubjek)->whereIn('id_indikator', static fn ($q) => $q->select('id')->from('analisis_indikator')->where(['id_master' => $master]))->delete();
- redirect(ci_route('analisis_respon.' . $master . '.form', $idSubjek));
- }
-
- public function data_ajax(): void
- {
- $data['analisis_master'] = $this->analisisMaster;
- view('analisis_respon.import.data_ajax', $data);
- }
-
- /**
- * Unduh data analisis respon
- *
- * @param int $tipe | 1. Dengan isian data, 2. Dengan kode isian
- * @param mixed $master
- */
- public function data_unduh($master): void
- {
- $paramDatatable = json_decode((string) $this->input->post('params'), 1);
- $_GET = $paramDatatable;
- $tipe = $this->input->post('tipe') ?? 1;
- $data['subjek_tipe'] = $this->analisisMaster->subjek_tipe;
- $data['main'] = $this->sumberData()->get()->map(function ($item) {
-
- $par = AnalisisRespon::selectRaw('kode_jawaban, asign, jawaban, analisis_respon.id_indikator, analisis_respon.id_parameter AS korek')
- ->from('analisis_respon')
- ->join('analisis_parameter', 'analisis_parameter.id', '=', 'analisis_respon.id_parameter')
- ->where('analisis_respon.id_periode', $this->periodeAktif->id)
- ->where('analisis_respon.id_subjek', $item->id)
- ->orderBy('analisis_respon.id_indikator')
- ->get()
- ->toArray();
- $item['par'] = $par;
-
- return $item;
- })->toArray();
- $data['periode'] = $this->periodeAktif->id;
- $data['indikator'] = AnalisisIndikator::indikatorUnduh($master);
- $data['tipe'] = $tipe;
- $key = ($data['periode'] + 3) * ($this->analisisMaster->id + 7) * ($this->analisisMaster->subjek_tipe * 3);
- $data['key'] = 'AN' . $key;
-
- $data['span_kolom'] = match ($this->analisisMaster->subjek_tipe) {
- 5, 6 => 3,
- 7 => 5,
- 8 => 6,
- default => 7,
- };
- $data['judul'] = Analisis::judul_subjek($this->analisisMaster->subjek_tipe);
-
- view('analisis_respon.import.data_unduh', $data);
- }
-
- public function import($master, $op = 0): void
- {
- isCan('u');
- $data['form_action'] = ci_route("analisis_respon.{$master}.import_proses", $op);
-
- view('analisis_respon.import.import', $data);
- }
-
- public function import_proses($master, $op = 0): void
- {
- isCan('u');
- $periode = $this->periodeAktif->id;
- $subjekTipe = $this->analisisMaster->subjek_tipe;
- DB::beginTransaction();
-
- try {
- $result = (new AnalisisRespon())->import_respon($master, $periode, $subjekTipe, $op);
- DB::commit();
- redirect_with('success', 'Data berhasil diimport', ci_route('analisis_respon.' . $master));
- } catch (Exception $e) {
- DB::rollBack();
- redirect_with('error', 'Data gagal diimport ' . $result['pesan'] . ' ' . $e->getMessage(), ci_route('analisis_respon.' . $master));
- }
- }
-
- public function form_impor_bdt($master): void
- {
- isCan('u');
- $data['form_action'] = ci_route("analisis_respon.{$master}.impor_bdt");
- $data['analisis_master'] = $this->analisisMaster;
- $data['formatImpor'] = ci_route('unduh', encrypt(DEFAULT_LOKASI_IMPOR . 'contoh-data-bdt2015.xlsx'));
-
- view('analisis_respon.import.impor_bdt', $data);
- }
-
- public function impor_bdt($master): void
- {
- isCan('u');
- DB::beginTransaction();
-
- try {
- (new Bdt($master, $this->periodeAktif->id))->impor();
- DB::commit();
- redirect_with('success', 'Data berhasil diimport', ci_route('analisis_respon.' . $master));
- } catch (Exception $e) {
- DB::rollBack();
- redirect_with('error', 'Data gagal diimport ' . $e->getMessage(), ci_route('analisis_respon.' . $master));
- }
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_respon_child.php b/Modules/Analisis/Http/Controllers/Analisis_respon_child.php
deleted file mode 100644
index 1a17c03a1..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_respon_child.php
+++ /dev/null
@@ -1,132 +0,0 @@
-getPeriodeChild();
- $data['list_jawab'] = $this->listIndikatorChild($idSubjek, $per);
-
- return view('analisis_respon.child.form', $data);
- }
-
- public function updateChild($master, $parentSubjek, $idSubjek): void
- {
- isCan('u');
- DB::beginTransaction();
- $per = $this->getPeriodeChild();
-
- try {
- AnalisisRespon::updateKuisioner($master, $per, $_POST, $idSubjek);
- DB::commit();
- redirect_with('success', 'Berhasil Simpan Data Kuisioner', ci_route('analisis_respon.' . $master . '.form', $parentSubjek));
- } catch (Exception $e) {
- DB::rollBack();
- log_message('error', $e->getMessage());
- redirect_with('error', 'Gagal Ubah Data Kuisioner ' . $e->getMessage(), ci_route('analisis_respon.' . $master . '.form', $parentSubjek));
- }
- }
-
- public function listIndikatorChild($idSubjek, $periode)
- {
- $idChild = $this->analisisMaster->id_child;
- $per = $periode;
- $delik = session('delik');
- $data = AnalisisIndikator::where('id_master', $idChild)
- ->orderBy('nomor')
- ->get()
- ->toArray();
- $counter = count($data);
-
- for ($i = 0; $i < $counter; $i++) {
- $data[$i]['no'] = $i + 1;
-
- if ($data[$i]['id_tipe'] == 1 || $data[$i]['id_tipe'] == 2) {
- $data[$i]['parameter_respon'] = $this->list_jawab4($idSubjek, $data[$i]['id'], $per);
- } else {
- $data[$i]['parameter_respon'] = ($delik) ? '' : $this->list_jawab5($idSubjek, $data[$i]['id'], $per);
- }
- }
-
- return $data;
- }
-
- private function list_jawab4($id = 0, $in = 0, $per = 0)
- {
- $delik = session('delik');
- $query = AnalisisParameter::selectRaw('id as id_parameter,jawaban,kode_jawaban')
- ->where('id_indikator', $in)
- ->orderBy('kode_jawaban', 'ASC');
- if ($delik) {
- $query->selectRaw('0 as cek');
- } else {
- $query->selectRaw('(SELECT count(id_subjek) FROM analisis_respon WHERE id_parameter = analisis_parameter.id AND id_subjek =' . $id . ' AND id_periode=' . $per . ') as cek');
- }
-
- return $query->get()->toArray();
- }
-
- private function list_jawab5($id = 0, $in = 0, $per = 0)
- {
- return AnalisisRespon::selectRaw('analisis_parameter.id as id_parameter,analisis_parameter.jawaban')
- ->leftJoin('analisis_parameter', 'analisis_respon.id_parameter', '=', 'analisis_parameter.id')
- ->where(['analisis_respon.id_indikator' => $in, 'analisis_respon.id_subjek' => $id, 'analisis_respon.id_periode' => $per])
- ->get()
- ->toArray();
- }
-
- public function getPeriodeChild()
- {
- $idChild = $this->analisisMaster->id_child;
-
- return AnalisisPeriode::select('id')->where('id_master', $idChild)->where('aktif', 1)->first()->id;
- }
-}
diff --git a/Modules/Analisis/Http/Controllers/Analisis_statistik_jawaban.php b/Modules/Analisis/Http/Controllers/Analisis_statistik_jawaban.php
deleted file mode 100644
index 7f9bef293..000000000
--- a/Modules/Analisis/Http/Controllers/Analisis_statistik_jawaban.php
+++ /dev/null
@@ -1,284 +0,0 @@
-segment(2);
- $this->analisisMaster = AnalisisMaster::findOrFail($master);
- if ($master) {
- $this->periodeAktif = AnalisisPeriode::whereIdMaster($master)->where(['aktif' => StatusEnum::YA])->first();
- if (! $this->periodeAktif) {
- redirect_with('error', 'Tidak ada periode aktif. Untuk laporan ini harus ada periode aktif.', ci_route('analisis_periode', $master));
- }
- }
- view()->share([
- 'selectedMenu' => $this->selectedMenu,
- 'analisis_master' => $this->analisisMaster,
- ]);
- }
-
- public function index($master): void
- {
-
- $data['list_tipe'] = TipePertanyaanEnum::all();
- $data['list_kategori'] = AnalisisKategori::where(['id_master' => $master])->get();
- $data['wilayah'] = Wilayah::treeAccess();
-
- view('analisis_statistik_jawaban.index', $data);
- }
-
- public function datatables($master)
- {
- if ($this->input->is_ajax_request()) {
- $sumberData = $this->sumberData();
- $idCluster = $this->getCluster();
- $sbj = $this->getQuerySubject($idCluster);
- $per = $this->periodeAktif->id;
- $listCluster = http_build_query($this->listCluster);
-
- return datatables()->of($sumberData)
- ->addIndexColumn()
- ->addColumn('par', static fn ($q) => DB::select("SELECT i.id,i.kode_jawaban,i.jawaban,(SELECT COUNT(r.id_subjek) FROM analisis_respon r {$sbj} WHERE r.id_parameter = i.id AND r.id_periode = {$per}) AS jml_p FROM analisis_parameter i WHERE i.id_indikator = {$q->id} ORDER BY i.kode_jawaban AND i.config_id = " . identitas('id')))
- ->editColumn('bobot', static fn ($q) => 'id) . '?' . $listCluster . '" > ' . $q->bobot . '')
- ->addColumn('list_cluster', $listCluster)
- ->editColumn('act_analisis', static fn ($q) => StatusEnum::valueOf($q->act_analisis))
- ->editColumn('id_tipe', static fn ($q) => TipePertanyaanEnum::valueOf($q->id_tipe))
- ->rawColumns(['ceklist', 'bobot'])
- ->make();
- }
-
- return show_404();
- }
-
- private function sumberData()
- {
- $idCluster = $this->getCluster();
- $sbj = $this->getQuerySubject($idCluster);
- $analisisMaster = $this->analisisMaster;
-
- return AnalisisIndikator::with(['kategori'])
- ->selectRaw('analisis_indikator.*')
- ->selectRaw("(SELECT COUNT(DISTINCT r.id_subjek) AS jml FROM analisis_respon r {$sbj} WHERE r.id_indikator = analisis_indikator.id AND r.id_periode = {$this->periodeAktif->id} AND id_parameter > 0) as bobot")
- ->where(['id_master' => $analisisMaster->id]);
- }
-
- private function getCluster()
- {
- $dusun = $this->input->get('dusun') ?? null;
- $rw = $this->input->get('rw') ?? null;
- $rt = $this->input->get('rt') ?? null;
- if ($rt) {
- [$namaDusun, $namaRw] = explode('__', $rw);
- $this->listCluster['dusun'] = $namaDusun;
- $this->listCluster['rw'] = $namaRw;
- $this->listCluster['rt'] = $rt;
- }
- $idCluster = $rt ? [$rt] : [];
-
- if (empty($idCluster) && ! empty($rw)) {
- if (Str::contains($rw, '__') ) {
- [$namaDusun, $namaRw] = explode('__', $rw);
- } else {
- $namaDusun = $dusun;
- $namaRw = $rw;
- }
-
- $idCluster = Wilayah::whereDusun($namaDusun)->whereRw($namaRw)->select(['id'])->get()->pluck('id')->toArray();
- $this->listCluster['dusun'] = $namaDusun;
- $this->listCluster['rw'] = $namaRw;
- }
-
- if (empty($idCluster) && ! empty($dusun)) {
- $idCluster = Wilayah::whereDusun($dusun)->select(['id'])->get()->pluck('id')->toArray();
- $this->listCluster['dusun'] = $dusun;
- }
-
- return $idCluster;
- }
-
- private function getQuerySubject($idCluster)
- {
- $sbj = '';
- $clusterStr = $idCluster ? ' and a.id in (' . implode(',', $idCluster) . ')' : '';
-
- switch ($this->analisisMaster->subjek_tipe) {
- case AnalisisRefSubjekEnum::PENDUDUK: $sbj = 'JOIN tweb_penduduk p ON r.id_subjek = p.id JOIN tweb_wil_clusterdesa a ON p.id_cluster = a.id ';
- break;
-
- case AnalisisRefSubjekEnum::KELUARGA: $sbj = 'JOIN tweb_keluarga v ON r.id_subjek = v.id JOIN tweb_penduduk p ON v.nik_kepala = p.id JOIN tweb_wil_clusterdesa a ON p.id_cluster = a.id ';
- break;
-
- case AnalisisRefSubjekEnum::RUMAH_TANGGA: $sbj = 'JOIN tweb_rtm v ON r.id_subjek = v.id JOIN tweb_penduduk p ON v.nik_kepala = p.id JOIN tweb_wil_clusterdesa a ON p.id_cluster = a.id ';
- break;
-
- case AnalisisRefSubjekEnum::KELOMPOK: $sbj = 'JOIN kelompok v ON r.id_subjek = v.id JOIN tweb_penduduk p ON v.id_ketua = p.id JOIN tweb_wil_clusterdesa a ON p.id_cluster = a.id ';
- break;
- }
- $sbj .= $clusterStr;
-
- return $sbj;
- }
-
- public function grafik_parameter($master, $id = ''): void
- {
- if ($this->input->get('dusun')) {
- $this->filterColumn['dusun'] = $this->input->get('dusun');
- }
- if ($this->input->get('rw')) {
- $this->filterColumn['rw'] = $this->input->get('rw');
- }
- if ($this->input->get('rt')) {
- $this->filterColumn['rt'] = $this->input->get('rt');
- }
-
- $idCluster = $this->getCluster();
- $sbj = $this->getQuerySubject($idCluster);
- $per = $this->periodeAktif->id;
- $data['form_action'] = ci_route("analisis_statistik_jawaban.{$master}.grafik_parameter", $id);
- $data['filterColumn'] = $this->filterColumn;
- $data['wilayah'] = Wilayah::treeAccess();
- $data['analisis_statistik_jawaban'] = AnalisisIndikator::findOrFail($id);
- $data['analisis_master'] = $this->analisisMaster;
- $data['main'] = AnalisisParameter::selectRaw('analisis_parameter.*')
- ->selectRaw("(SELECT COUNT(r.id_subjek) FROM analisis_respon r {$sbj} WHERE r.id_parameter = analisis_parameter.id AND r.id_periode = {$per}) as nilai")
- ->where('id_indikator', $id)->orderBy('kode_jawaban')->get()->toArray();
-
- view('analisis_statistik_jawaban.parameter.grafik_table', $data);
- }
-
- public function subjek_parameter($master, $id, $par): void
- {
-
- if ($this->input->get('dusun')) {
- $this->filterColumn['dusun'] = $this->input->get('dusun');
- }
- if ($this->input->get('rw')) {
- $this->filterColumn['rw'] = $this->input->get('rw');
- }
- if ($this->input->get('rt')) {
- $this->filterColumn['rt'] = $this->input->get('rt');
- }
-
- $idCluster = $this->getCluster();
- $sbj = $this->getQuerySubject($idCluster);
- $per = $this->periodeAktif->id;
- $listCluster = http_build_query($this->listCluster);
- $sql = "SELECT p.id AS id_pend,r.id_subjek,p.nama,p.nik,(SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(tanggallahir)), '%Y')+0 FROM tweb_penduduk WHERE id = p.id AND config_id = " . identitas('id') . ") AS umur,p.sex,a.dusun,a.rw,a.rt FROM analisis_respon r {$sbj} WHERE r.id_parameter = {$par} AND r.id_periode = {$per}";
- $data['filterColumn'] = $this->filterColumn;
- $data['wilayah'] = Wilayah::treeAccess();
- $data['form_action'] = ci_route("analisis_statistik_jawaban.{$master}.subjek_parameter.{$id}", $par);
- $data['analisis_statistik_pertanyaan'] = AnalisisIndikator::findOrFail($id);
- $data['analisis_statistik_jawaban'] = AnalisisParameter::findOrFail($par);
- $data['cetak_action'] = ci_route("analisis_statistik_jawaban.{$master}.cetak_subjek.{$id}.{$par}.cetak") . '?' . $listCluster;
- $data['unduh_action'] = ci_route("analisis_statistik_jawaban.{$master}.cetak_subjek.{$id}.{$par}.unduh") . '?' . $listCluster;
- $data['analisis_master'] = $this->analisisMaster;
- $data['main'] = DB::select($sql);
-
- view('analisis_statistik_jawaban.parameter.subjek_table', $data);
- }
-
- public function cetak($master): void
- {
- $tipe = $this->input->post('tipe') ?? 'cetak';
- if ($tipe == 'unduh') {
- $tgl = date('d_m_Y');
- header('Content-type: application/octet-stream');
- header("Content-Disposition: attachment; filename=statistik_analisis_jawaban_{$tgl}.xls");
- header('Pragma: no-cache');
- header('Expires: 0');
- }
- $paramDatatable = json_decode((string) $this->input->post('params'), 1);
- $_GET = $paramDatatable;
- $idCluster = $this->getCluster();
- $sbj = $this->getQuerySubject($idCluster);
- $per = $this->periodeAktif->id;
- $data['main'] = $this->sumberData()->get()->map(static function ($item) use ($per, $sbj) {
- $par = DB::select("SELECT i.id,i.kode_jawaban,i.jawaban,(SELECT COUNT(r.id_subjek) FROM analisis_respon r {$sbj} WHERE r.id_parameter = i.id AND r.id_periode = {$per}) AS jml_p FROM analisis_parameter i WHERE i.id_indikator = {$item->id} ORDER BY i.kode_jawaban AND i.config_id = " . identitas('id'));
- $item['par'] = $par;
-
- return $item;
- })->toArray();
- view('analisis_statistik_jawaban.table_print', $data);
- }
-
- public function cetak_subjek($master, $id, $par, $tipe = 'cetak'): void
- {
- if ($tipe == 'unduh') {
- $tgl = date('d_m_Y');
- header('Content-type: application/octet-stream');
- header("Content-Disposition: attachment; filename=subjek_analisis_{$tgl}.xls");
- header('Pragma: no-cache');
- header('Expires: 0');
- }
-
- $idCluster = $this->getCluster();
- $sbj = $this->getQuerySubject($idCluster);
- $per = $this->periodeAktif->id;
- $data['analisis_statistik_pertanyaan'] = AnalisisIndikator::findOrFail($id);
- $data['analisis_statistik_jawaban'] = AnalisisParameter::findOrFail($par);
- $sql = "SELECT p.id AS id_pend,r.id_subjek,p.nama,p.nik,(SELECT DATE_FORMAT(FROM_DAYS(TO_DAYS(NOW())-TO_DAYS(tanggallahir)), '%Y')+0 FROM tweb_penduduk WHERE id = p.id AND config_id = " . identitas('id') . ") AS umur,p.sex,a.dusun,a.rw,a.rt FROM analisis_respon r {$sbj} WHERE r.id_parameter = {$par} AND r.id_periode = {$per}";
- $data['main'] = DB::select($sql);
- view('analisis_statistik_jawaban.parameter.subjek_print', $data);
- }
-}
diff --git a/Modules/Analisis/Libraries/Analisis.php b/Modules/Analisis/Libraries/Analisis.php
index be0d6c7a3..ad839ead1 100644
--- a/Modules/Analisis/Libraries/Analisis.php
+++ b/Modules/Analisis/Libraries/Analisis.php
@@ -1,451 +1,521 @@
- 'Nama',
- 'nomor' => 'NIK',
- 'kolom' => [
- ['data' => 'nid', 'name' => 'nik'],
- ['data' => 'nama', 'name' => 'nama'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::KELUARGA:
- $judul = [
- 'nama' => 'Kepala Keluarga',
- 'nomor' => 'Nomor KK',
- 'kolom' => [
- ['data' => 'nid', 'name' => 'no_kk'],
- ['data' => 'nama', 'name' => 'penduduk_hidup.nama'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::RUMAH_TANGGA:
- $judul = [
- 'nama' => 'Kepala Rumah Tangga',
- 'nomor' => 'Nomor Rumah Tangga',
- 'kolom' => [
- ['data' => 'nid', 'name' => 'tweb_rtm.no_kk'],
- ['data' => 'nama', 'name' => 'penduduk_hidup.nama'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::KELOMPOK:
- $judul = [
- 'nama' => 'Nama Kelompok',
- 'nomor' => 'ID Kelompok',
- 'kolom' => [
- ['data' => 'nid', 'name' => 'kode'],
- ['data' => 'nama', 'name' => 'nama'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::DESA:
- $desa = ucwords(setting('sebutan_desa'));
- $judul = [
- 'nama' => "Nama {$desa}",
- 'nomor' => "Kode {$desa}",
- 'kolom' => [
- ['data' => 'nid', 'name' => 'kode_desa'],
- ['data' => 'nama', 'name' => 'nama_desa'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::DUSUN:
- $dusun = ucwords(setting('sebutan_dusun'));
- $judul = [
- 'nama' => "Nama {$dusun}",
- 'nomor' => $dusun,
- 'kolom' => [
- ['data' => 'nid', 'name' => 'dusun'],
- ['data' => 'nama', 'name' => 'dusun'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::RW:
- $judul = [
- 'nama' => 'Nama ' . setting('sebutan_dusun') . '/RW',
- 'nomor' => 'RW',
- 'kolom' => [
- ['data' => 'nid', 'name' => 'rw'],
- ['data' => 'nama', 'name' => 'rw'],
- ],
- ];
- break;
-
- case AnalisisRefSubjekEnum::RT:
- $judul = [
- 'nama' => 'Nama ' . setting('sebutan_dusun') . '/RW/RT',
- 'nomor' => 'RT',
- 'kolom' => [
- ['data' => 'nid', 'name' => 'rt'],
- ['data' => 'nama', 'name' => 'rt'],
- ],
- ];
- break;
-
- default:
- $judul = null;
- }
-
- return $judul;
- }
-
- public static function sumberData($subjek_tipe, $idCluster = [])
- {
- $sumber = null;
- $utama = '';
-
- switch ($subjek_tipe) {
- case AnalisisRefSubjekEnum::PENDUDUK:
- $utama = 'penduduk_hidup';
- $sumber = PendudukHidup::join('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->join('tweb_keluarga', 'tweb_keluarga.id', '=', 'penduduk_hidup.id_kk')
- ->when($idCluster, static fn ($q) => $q->whereIn('penduduk_hidup.id_cluster', $idCluster))
- ->selectRaw('penduduk_hidup.id, nik AS nid, penduduk_hidup.nama, tweb_keluarga.no_kk as kk, tweb_keluarga.alamat, sex, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt');
- break;
-
- case AnalisisRefSubjekEnum::KELUARGA:
- $utama = 'keluarga_aktif';
- $sumber = KeluargaAktif::join('penduduk_hidup', 'keluarga_aktif.nik_kepala', '=', 'penduduk_hidup.id')
- ->join('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->when($idCluster, static fn ($q) => $q->whereIn('penduduk_hidup.id_cluster', $idCluster))
- ->selectRaw('keluarga_aktif.id, keluarga_aktif.no_kk AS nid, penduduk_hidup.nama, penduduk_hidup.nik as kk, keluarga_aktif.alamat, penduduk_hidup.sex, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt');
- break;
-
- case AnalisisRefSubjekEnum::RUMAH_TANGGA:
- $utama = 'tweb_rtm';
- $sumber = Rtm::join('penduduk_hidup', 'tweb_rtm.nik_kepala', '=', 'penduduk_hidup.id')
- ->join('tweb_keluarga', 'tweb_keluarga.id', '=', 'penduduk_hidup.id_kk')
- ->join('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->when($idCluster, static fn ($q) => $q->whereIn('penduduk_hidup.id_cluster', $idCluster))
- ->selectRaw('tweb_rtm.id, tweb_rtm.no_kk AS nid, penduduk_hidup.nama, penduduk_hidup.nik as kk, tweb_keluarga.alamat, penduduk_hidup.sex, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt');
- break;
-
- case AnalisisRefSubjekEnum::KELOMPOK:
- $utama = 'kelompok';
- $sumber = Kelompok::leftJoin('penduduk_hidup', 'kelompok.id_ketua', '=', 'penduduk_hidup.id')
- ->join('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->when($idCluster, static fn ($q) => $q->whereIn('penduduk_hidup.id_cluster', $idCluster))
- ->selectRaw('kelompok.id, kelompok.kode AS nid, kelompok.nama, penduduk_hidup.sex, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt');
- break;
-
- case AnalisisRefSubjekEnum::DESA:
- $utama = 'config';
- $sumber = Config::selectRaw('config.id, config.kode_desa as nid, config.nama_desa as nama, "-" as sex, "-" as dusun, "-" as rw, "-" as rt');
- break;
-
- case AnalisisRefSubjekEnum::DUSUN:
- $sebutanDusun = setting('sebutan_dusun');
- $utama = 'tweb_wil_clusterdesa';
- $sumber = Wilayah::where('rt', '0')->where('rw', '0')
- ->when($idCluster, static fn ($q) => $q->whereIn('id', $idCluster))
- ->selectRaw("id, dusun AS nid, CONCAT(UPPER('" . $sebutanDusun . " '), dusun) as nama, '-' as sex, dusun, '-' as rw, '-' as rt");
- break;
-
- case AnalisisRefSubjekEnum::RW:
- $sebutanDusun = setting('sebutan_dusun');
- $utama = 'tweb_wil_clusterdesa';
- $sumber = Wilayah::where('rt', '0')->where('rw', '!=', '0')->where('rw', '!=', '-')
- ->when($idCluster, static fn ($q) => $q->whereIn('id', $idCluster))
- ->selectRaw("id, rw AS nid, CONCAT( UPPER('" . $sebutanDusun . " '), dusun, ' RW ', rw) as nama, '-' as sex, dusun, rw, '-' as rt");
- break;
-
- case AnalisisRefSubjekEnum::RT:
- $sebutanDusun = setting('sebutan_dusun');
- $utama = 'tweb_wil_clusterdesa';
- $sumber = Wilayah::where('rt', '!=', '0')->where('rt', '!=', '-')
- ->when($idCluster, static fn ($q) => $q->whereIn('id', $idCluster))
- ->selectRaw("id, rt AS nid, CONCAT( UPPER('" . $sebutanDusun . " '), dusun, ' RW ', rw, ' RT ', rt) as nama, '-' as sex, dusun, rw, rt");
- break;
- }
-
- return ['sumber' => $sumber, 'utama' => $utama];
- }
-
- public function getSubjek($analisisMaster, $id)
- {
- $sebutan_dusun = ucwords(setting('sebutan_dusun'));
- $subjekTipe = $analisisMaster->subjek_tipe;
- $sumber = null;
-
- switch ($subjekTipe) {
- case AnalisisRefSubjekEnum::PENDUDUK:
- $sumber = PendudukHidup::selectRaw('penduduk_hidup.*, penduduk_hidup.nik AS nid, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt')
- ->selectRaw("CONCAT('{$sebutan_dusun} ', tweb_wil_clusterdesa.dusun, ', RT ', tweb_wil_clusterdesa.rt, ' / RW ', tweb_wil_clusterdesa.rw) as wilayah")
- ->join('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->where('penduduk_hidup.id', $id);
- break;
-
- case AnalisisRefSubjekEnum::KELUARGA:
- $sumber = KeluargaAktif::selectRaw('keluarga_aktif.*, keluarga_aktif.no_kk AS nid, penduduk_hidup.nik AS nik_kepala, penduduk_hidup.nama, penduduk_hidup.sex, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt')
- ->selectRaw("CONCAT('{$sebutan_dusun} ', tweb_wil_clusterdesa.dusun, ', RT ', tweb_wil_clusterdesa.rt, ' / RW ', tweb_wil_clusterdesa.rw) as wilayah")
- ->leftJoin('penduduk_hidup', 'keluarga_aktif.nik_kepala', '=', 'penduduk_hidup.id')
- ->leftJoin('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->where('keluarga_aktif.id', $id);
-
- break;
-
- case AnalisisRefSubjekEnum::RUMAH_TANGGA:
- $sumber = Rtm::selectRaw('tweb_rtm.id, tweb_rtm.no_kk AS nid, penduduk_hidup.nama, penduduk_hidup.sex, tweb_wil_clusterdesa.dusun, tweb_wil_clusterdesa.rw, tweb_wil_clusterdesa.rt')
- ->join('penduduk_hidup', 'tweb_rtm.nik_kepala', '=', 'penduduk_hidup.id')
- ->join('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->where('tweb_rtm.id', $id);
- break;
-
- case AnalisisRefSubjekEnum::KELOMPOK:
- $sumber = Kelompok::selectRaw('kelompok.nama AS no_kk, penduduk_hidup.nama')
- ->leftJoin('penduduk_hidup', 'kelompok.id_ketua', '=', 'penduduk_hidup.id')
- ->leftJoin('tweb_wil_clusterdesa', 'penduduk_hidup.id_cluster', '=', 'tweb_wil_clusterdesa.id')
- ->where('kelompok.id', $id);
- break;
-
- case AnalisisRefSubjekEnum::DESA:
- $sumber = Config::selectRaw("config.id, config.kode_desa AS nid, config.nama_desa as nama, '-' as sex, '-' as dusun, '-' as rw, '-' as rt")
- ->selectRaw("
- config.nama_desa, config.kode_desa, config.kode_pos, config.alamat_kantor, config.telepon as no_telepon_kantor_desa, config.email_desa, CONCAT('Lintang : ', config.lat, ', ', 'Bujur : ', config.lng) as titik_koordinat_desa")
- ->selectRaw('
- tweb_desa_pamong.pamong_nip AS nip_kepala_desa,
- (case when tweb_penduduk.sex is not null then tweb_penduduk.sex else tweb_desa_pamong.pamong_sex end) as jk_kepala_desa,
- (case when tweb_penduduk.pendidikan_kk_id is not null then pendidikan_warga.nama else pendidikan_pamong.nama end) as pendidikan_kepala_desa,
- (case when tweb_penduduk.nama is not null then tweb_penduduk.nama else tweb_desa_pamong.pamong_nama end) AS nama_kepala_desa,
- tweb_penduduk.telepon as no_telepon_kepala_desa
- ')
- ->leftJoin('tweb_desa_pamong', 'config.pamong_id', '=', 'tweb_desa_pamong.pamong_id')
- ->leftJoin('tweb_penduduk', 'tweb_desa_pamong.id_pend', '=', 'tweb_penduduk.id')
- ->leftJoin('tweb_penduduk_pendidikan_kk as pendidikan_warga', 'tweb_penduduk.pendidikan_kk_id', '=', 'pendidikan_warga.id')
- ->leftJoin('tweb_penduduk_pendidikan_kk as pendidikan_pamong', 'tweb_desa_pamong.pamong_pendidikan', '=', 'pendidikan_pamong.id')
- ->where('config.id', $id);
- break;
-
- case AnalisisRefSubjekEnum::DUSUN:
- $sumber = Wilayah::selectRaw("id, dusun AS nid, UPPER('{$sebutan_dusun}') as nama, '-' as sex, dusun, '-' as rw, '-' as rt")
- ->where('rt', '0')->where('rw', '0')->where('tweb_wil_clusterdesa.id', $id);
- break;
-
- case AnalisisRefSubjekEnum::RW:
- $sumber = Wilayah::selectRaw("id, rw AS nid, CONCAT( UPPER('{$sebutan_dusun} '), dusun, ' RW ', rw) as nama, '-' as sex, dusun, rw, '-' as rt")
- ->where('rt', '0')->where('rw', '!=', '0')->where('tweb_wil_clusterdesa.id', $id);
- break;
-
- case AnalisisRefSubjekEnum::RT:
- $sumber = Wilayah::selectRaw("id, rt AS nid, CONCAT( UPPER('{$sebutan_dusun} '), dusun, ' RW ', rw, ' RT ', rt) as nama, '-' as sex, dusun, rw, rt")
- ->where('rt', '!=', '0')->where('rt', '!=', '-')->where('tweb_wil_clusterdesa.id', $id);
- break;
-
- default: return null;
- }
- $data = $sumber->first()?->toArray();
-
- // Data tambahan subjek desa
- if ($subjekTipe == 5) {
- $tambahan = [
- 'jumlah_total_penduduk' => PendudukHidup::count(),
- 'jumlah_penduduk_laki_laki' => PendudukHidup::where('sex', JenisKelaminEnum::LAKI_LAKI)->count(),
- 'jumlah_penduduk_perempuan' => PendudukHidup::where('sex', JenisKelaminEnum::PEREMPUAN)->count(),
- 'jumlah_penduduk_pedatang' => PendudukHidup::where('status', 2)->count(),
- 'jumlah_penduduk_yang_pergi' => LogPenduduk::where('kode_peristiwa', 3)->count(),
- 'jumlah_total_kepala_keluarga' => KeluargaAktif::leftJoin('penduduk_hidup', 'keluarga_aktif.nik_kepala', '=', 'penduduk_hidup.id')->count(),
- 'jumlah_kepala_keluarga_laki_laki' => KeluargaAktif::leftJoin('penduduk_hidup', 'keluarga_aktif.nik_kepala', '=', 'penduduk_hidup.id')->where('sex', JenisKelaminEnum::LAKI_LAKI)->count(),
- 'jumlah_kepala_keluarga_perempuan' => KeluargaAktif::leftJoin('penduduk_hidup', 'keluarga_aktif.nik_kepala', '=', 'penduduk_hidup.id')->where('sex', JenisKelaminEnum::PEREMPUAN)->count(),
- 'jumlah_peserta_bpjs' => PendudukHidup::whereNotNull('bpjs_ketenagakerjaan')->count(),
- ];
-
- $data = array_merge($data, $tambahan);
- }
-
- return $data;
- }
-
- public function listAnggota($analisisMaster, $id)
- {
- $subjek = $analisisMaster->subjek_tipe;
- if (in_array($subjek, [AnalisisRefSubjekEnum::KELUARGA, AnalisisRefSubjekEnum::RUMAH_TANGGA])) {
- switch ($subjek) {
- case AnalisisRefSubjekEnum::KELUARGA:
- return PendudukHidup::where('id_kk', $id)->orderBy('kk_level')->get()->toArray();
-
- case AnalisisRefSubjekEnum::RUMAH_TANGGA:
- return PendudukHidup::where('id_rtm', $id)->orderBy('rtm_level')->get()->toArray();
-
- default: return null;
- }
- }
-
- return null;
- }
-
- public function listIndikator($analisisMaster, $periode, $id)
- {
- $per = $periode;
- $delik = session('delik');
-
- $data = AnalisisIndikator::with(['kategori'])
- ->where('id_master', $analisisMaster->id)
- ->orderByRaw("LPAD(nomor, 10, ' ') ASC")
- ->get()
- ->toArray();
- $counter = count($data);
-
- for ($i = 0; $i < $counter; $i++) {
- $data[$i]['no'] = $i + 1;
- $data[$i]['kategori'] = $data[$i]['kategori']['kategori'];
- if ($data[$i]['id_tipe'] == 1 || $data[$i]['id_tipe'] == 2) {
- $data[$i]['parameter_respon'] = $this->listJawab2($id, $data[$i]['id'], $per);
- } else {
- $data[$i]['parameter_respon'] = $delik ? '' : $this->listJawab3($id, $data[$i]['id'], $per);
- }
- }
-
- return $data;
- }
-
- private function listJawab2($id = 0, $in = 0, $per = 0)
- {
- $delik = session('delik');
- $query = AnalisisParameter::selectRaw('id as id_parameter,jawaban,kode_jawaban')
- ->where('id_indikator', $in)
- ->orderBy('kode_jawaban', 'ASC');
- if ($delik) {
- $query->selectRaw('0 as cek');
- } else {
- $query->selectRaw('(SELECT count(id_subjek) FROM analisis_respon WHERE id_parameter = analisis_parameter.id AND id_subjek =' . $id . ' AND id_periode=' . $per . ') as cek');
- }
-
- return $query->get()->toArray();
- }
-
- private function listJawab3($id = 0, $in = 0, $per = 0)
- {
- return AnalisisRespon::selectRaw('analisis_parameter.id as id_parameter,analisis_parameter.jawaban')
- ->leftJoin('analisis_parameter', 'analisis_respon.id_parameter', '=', 'analisis_parameter.id')
- ->where(['analisis_respon.id_indikator' => $in, 'analisis_respon.id_subjek' => $id, 'analisis_respon.id_periode' => $per])
- ->get()
- ->toArray();
- }
-
- public function listBukti($analisisMaster, $periode, $id)
- {
- $per = $periode;
-
- return AnalisisResponBukti::select(['pengesahan'])
- ->where('id_subjek', $id)
- ->where('id_master', $analisisMaster->id)
- ->where('id_periode', $per)
- ->orderBy('tgl_update', 'DESC')
- ->get()
- ->toArray();
- }
-
- private function listJawabLaporan($periode, $idSubjek, $in)
- {
- $per = $periode;
- $obj = AnalisisRespon::selectRaw('analisis_parameter.id as id_parameter, analisis_parameter.jawaban as jawaban,analisis_parameter.nilai')
- ->join('analisis_parameter', 'analisis_respon.id_parameter', '=', 'analisis_parameter.id')
- ->where('id_subjek', $idSubjek)
- ->where('id_periode', $per)
- ->where('analisis_respon.id_indikator', $in)
- ->first();
-
- $data['jawaban'] = $obj->jawaban ?? '-';
- $data['nilai'] = $obj->nilai ?? '0';
-
- return $data;
- }
-
- public function listIndikatorLaporan($analisisMaster, $periode, $id = 0)
- {
- $data = AnalisisIndikator::where('id_master', $analisisMaster->id)->orderBy('nomor')->get()->toArray();
- $counter = count($data);
-
- for ($i = 0; $i < $counter; $i++) {
- $data[$i]['no'] = $i + 1;
- $ret = $this->listJawabLaporan($periode, $id, $data[$i]['id']);
- $data[$i]['jawaban'] = $ret['jawaban'];
- $data[$i]['nilai'] = $ret['nilai'];
- $data[$i]['poin'] = $data[$i]['bobot'] * $ret['nilai'];
- }
-
- return $data;
- }
-
- public function multi_jawab($master)
- {
- $kf = session('jawab') ?? '7777777';
-
- $data = AnalisisIndikator::selectRaw('analisis_indikator.pertanyaan,analisis_indikator.nomor,analisis_parameter.jawaban,analisis_parameter.id AS id_jawaban,analisis_parameter.kode_jawaban')
- ->selectRaw("(SELECT count(id) FROM analisis_parameter WHERE id IN ({$kf}) AND id = analisis_parameter.id AND analisis_indikator.config_id = " . identitas('id') . ') AS cek')
- ->where('id_master', $master)
- ->join('analisis_parameter', 'analisis_parameter.id_indikator', '=', 'analisis_indikator.id')
- ->orderBy('nomor')->orderBy('kode_jawaban')->get()->toArray();
- $counter = count($data);
-
- for ($i = 0; $i < $counter; $i++) {
- $data[$i]['no'] = $i + 1;
- }
-
- return $data;
- }
-}
+ 2,
- 'nama' => 80,
- 'nik' => 81,
- 'rtm_level' => 82,
- 'awal_respon_rt' => 14,
- 'awal_respon_penduduk' => 82,
- ];
- private $kolom_subjek;
- private $kolom_indikator_pertama;
- private $list_id_subjek;
-
- public function __construct($idMaster, $periode)
- {
- $this->idMaster = $idMaster;
- $this->periode = $periode;
- $this->analisisMaster = AnalisisMaster::findOrFail($idMaster);
- }
-
- private function file_import_valid()
- {
- // error 1 = UPLOAD_ERR_INI_SIZE; lihat Upload.php
- // TODO: pakai cara upload yg disediakan Codeigniter
- if ($_FILES['bdt']['error'] == 1) {
- $upload_mb = max_upload();
- $_SESSION['error_msg'] .= ' -> Ukuran file melebihi batas ' . $upload_mb . ' MB';
- $_SESSION['success'] = -1;
-
- return false;
- }
- $tipe_file = TipeFile($_FILES['bdt']);
- $mime_type_excel = ['application/vnd.ms-excel', 'application/octet-stream'];
- if (! in_array($tipe_file, $mime_type_excel)) {
- $_SESSION['error_msg'] .= ' -> Jenis file salah: ' . $tipe_file;
- $_SESSION['success'] = -1;
-
- return false;
- }
-
- return true;
- }
-
- /*
- * 1. Impor pengelompokan rumah tangga
- * 2. Impor data BDT 2015 ke dalam analisis_respon
- *
- * Abaikan subjek di data BDT yang tidak ada di database
- */
- public function impor(): void
- {
- $_SESSION['error_msg'] = '';
- $_SESSION['success'] = 1;
- if ($this->file_import_valid() == false) {
- return;
- }
-
- // Pakai parameter 'false' untuk mengurangi penggunaan memori
- // https://github.com/jasonrogena/php-excel-reader/issues/96
- $data = new Spreadsheet_Excel_Reader($_FILES['bdt']['tmp_name'], false);
- // Baca jumlah baris berkas BDT
- $this->jml_baris = $data->rowcount($sheet_index = 0);
- $this->baris_pertama = $this->cari_baris_pertama($data, $this->jml_baris);
- if ($this->baris_pertama <= 0) {
- $_SESSION['error_msg'] .= ' -> Tidak ada data';
- $_SESSION['success'] = -1;
-
- return;
- }
-
- // BDT2015 terbatas pada subjek rumah tangga dan penduduk
- if ($_SESSION['subjek_tipe'] == 3) {
- // Rumah tangga
- $this->kolom_subjek = $this->kolom['id_rtm'];
- $this->kolom_indikator_pertama = $this->kolom['awal_respon_rt'];
- } else {
- // Penduduk
- $this->kolom_subjek = $this->kolom['nik'];
- $this->kolom_indikator_pertama = $this->kolom['awal_respon_penduduk'];
- }
-
- $data_sheet = $data->sheets[0]['cells'];
- $this->impor_respon($data_sheet);
- }
-
- private function impor_respon($data_sheet): void
- {
- $gagal = 0;
- $ada = 0;
- $sudah_proses = [];
- $per = $this->periode;
- $indikator = AnalisisIndikator::where('id_master', $this->idMaster)->orderBy('id')->get()->toArray();
-
- $respon = [];
-
- for ($i = $this->baris_pertama; $i <= $this->jml_baris; $i++) {
- $data_subjek = $this->tulis_rtm($data_sheet[$i], $rtm);
- if (! $data_subjek) {
- $gagal++;
-
- continue; // Jangan impor jika NIK tidak ada di database
- }
- // Proses setiap subjek sekali saja
- if (! in_array($data_sheet[$i][$this->kolom_subjek], $sudah_proses)) {
- // $list_id_subjek[nik] = id-penduduk atau $list_id_subjek[id_rtm] = id-rumah-tangga
- if ($this->analisisMaster->subjek_tipe == 3) {
- $this->list_id_subjek[$data_sheet[$i][$this->kolom_subjek]] = $rtm;
- } else {
- $this->list_id_subjek[$data_sheet[$i][$this->kolom_subjek]] = $data_subjek['id_penduduk'];
- }
- $this->siapkan_respon($indikator, $per, $data_sheet[$i], $respon);
- $sudah_proses[] = $data_sheet[$i][$this->kolom_subjek];
- $ada++;
- }
- }
-
- // echo '
';
- // echo var_dump($this->list_id_subjek);
- $this->hapus_respon($this->list_id_subjek);
-
- // echo '
';
- // echo var_dump($respon);
-
- $outp = empty($respon) ? false : AnalisisRespon::insert($respon);
- (new AnalisisRespon())->pre_update($this->idMaster, $this->periode);
-
- if (! $outp) {
- $_SESSION['success'] = -1;
- }
-
- $nama_subjek = ($_SESSION['subjek_tipe'] == 3) ? 'RUMAH TANGGA' : 'PENDUDUK';
- echo "
JUMLAH PENDUDUK GAGAL : {$gagal}";
- echo "
JUMLAH {$nama_subjek} BERHASIL : {$ada}";
- echo 'LANJUT';
- }
-
- // Hapus semua respon untuk semua subjek pada periode aktif
- private function hapus_respon($list_id_subjek): void
- {
- if (empty($list_id_subjek)) {
- return;
- }
-
- $per = $this->periode;
- $prefix = $list_id_subjek_str = '';
-
- foreach ($list_id_subjek as $id) {
- $list_id_subjek_str .= $prefix . "'" . $id . "'";
- $prefix = ', ';
- }
-
- AnalisisRespon::where('id_periode', $per)->whereRaw("id_subjek in({$list_id_subjek_str})")->delete();
- }
-
- private function cari_baris_pertama(Spreadsheet_Excel_Reader $data, $jml_baris)
- {
- if ($jml_baris <= 1) {
- return 0;
- }
-
- $ada_baris = false;
-
- // Baris pertama baris judul kolom
- for ($i = 2; $i <= $jml_baris; $i++) {
- // Baris kedua yang mungkin ditambahkan untuk memudahkan penomoran kolom
- if ($data->val($i, 1) == 'KOLOM') {
- continue;
- }
- if (empty($data->val($i, 1))) {
- continue;
- }
- $ada_baris = true;
- $baris_pertama = $i;
- break;
- }
- if ($ada_baris) {
- return $baris_pertama;
- }
-
- return 0;
- }
-
- private function tulis_rtm($baris, &$rtm)
- {
- $id_rtm = $baris[$this->kolom['id_rtm']];
- $rtm_level = $baris[$this->kolom['rtm_level']];
- if ($rtm_level > 1) {
- $rtm_level = 2;
- } //Hanya rekam kepala & anggota rumah tangga
- $nik = $baris[$this->kolom['nik']];
-
- $pendudukObj = Penduduk::where('nik', $nik)->first();
- if (! $pendudukObj) {
- // Laporkan penduduk BDT tidak ada di database
- echo "" . $id_rtm . ' ' . $rtm_level . ' ' . $nik . ' ' . $baris[$this->kolom['nama']] . ' == tidak ditemukan di database penduduk.
';
-
- return false;
- }
-
- $rtm = Rtm::where('no_kk', $id_rtm)->first()->id;
- if ($rtm) {
- // Update rumah tangga
- if ($rtm_level == 1) {
- Rtm::where('id', $rtm)->update(['nik_kepala' => $pendudukObj->id]);
- }
- } else {
- // Tambah rumah tangga
- $rtm_data = [];
- $rtm_data['no_kk'] = $id_rtm;
- if ($rtm_level == 1) {
- $rtm_data['nik_kepala'] = $pendudukObj->id;
- }
-
- $rtm = (Rtm::create($rtm_data))->id;
- }
-
- $penduduk = [];
- $penduduk['id_rtm'] = $id_rtm;
- $penduduk['rtm_level'] = $rtm_level;
- $penduduk['updated_at'] = date('Y-m-d H:i:s');
- $penduduk['updated_by'] = auth()->id;
- Penduduk::where('nik', $nik)->update($penduduk);
- $penduduk['id_penduduk'] = $pendudukObj->id;
-
- return $penduduk;
- }
-
- private function siapkan_respon($indikator, $per, $baris, &$respon): void
- {
- foreach ($indikator as $key => $indi) {
- $isi = $baris[$this->kolom_indikator_pertama + $key];
-
- switch ($indi['id_tipe']) {
- case 1:
- $list_parameter = $this->parameter_pilihan_tunggal($indi['id'], $isi);
- break;
-
- case 2:
- $list_parameter = $this->parameter_pilihan_ganda($indi['id'], $isi);
- break;
-
- default:
- $list_parameter = $this->parameter_isian($indi['id'], $isi);
- break;
- }
-
- // Himpun respon untuk semua indikator untuk semua baris
- foreach ($list_parameter as $parameter) {
- if (! empty($parameter)) {
- $respon[] = [
- 'id_indikator' => $indi['id'],
- 'id_subjek' => $this->list_id_subjek[$baris[$this->kolom_subjek]],
- 'id_periode' => $per,
- 'id_parameter' => $parameter,
- ];
- }
- }
- }
- }
-
- private function parameter_pilihan_tunggal($id_indikator, $isi)
- {
- $param = AnalisisParameter::select('id')->where('id_indikator', $id_indikator)->where('kode_jawaban', $isi)->first()->toArray();
- if ($param) {
- $in_param = $param['id'];
- } elseif ($isi == '') {
- $in_param = 0;
- } else {
- $in_param = -1;
- }
-
- return [$in_param];
- }
-
- private function parameter_pilihan_ganda($id_indikator, $isi)
- {
- if (empty($isi)) {
- return [null];
- }
- $id_isi = explode(',', $isi);
- $in_param = [];
-
- foreach ($id_isi as $isi) {
- $param = AnalisisParameter::select('id')->where('id_indikator', $id_indikator)->where('kode_jawaban', $isi)->first()->toArray();
- if ($param['id'] != '') {
- $in_param[] = $param['id'];
- }
- }
-
- return $in_param;
- }
-
- private function parameter_isian($id_indikator, $isi)
- {
- if (empty($isi)) {
- return [null];
- }
- $param = AnalisisParameter::select('id')->where('id_indikator', $id_indikator)->where('jawaban', $isi)->first()->toArray();
-
- // apakah sdh ada jawaban yg sama
- if ($param) {
- $in_param = $param['id'];
- } else {
- // simpan setiap jawaban yang baru
- $parameter = [];
- $parameter['jawaban'] = $isi;
- $parameter['id_indikator'] = $id_indikator;
- $parameter['asign'] = 0;
-
- $in_param = (AnalisisParameter::create($parameter))->id;
- }
-
- return [$in_param];
- }
-}
+request = $request;
- }
-
- public function save(): array
- {
- $list_error = [];
-
- // SIMPAN ANALISIS MASTER
- $data_analisis_master = [
- 'nama' => $this->request->get('nama_form') == '' ? 'Response Google Form ' . date('dmY_His') : $this->request->get('nama_form'),
- 'subjek_tipe' => $this->request->get('subjek_analisis') == 0 ? 1 : $this->request->get('subjek_analisis'),
- 'id_kelompok' => 0,
- 'lock' => 1,
- 'format_impor' => 0,
- 'pembagi' => 1,
- 'id_child' => 0,
- 'deskripsi' => '',
- 'gform_id' => $this->request->get('gform-form-id'),
- 'gform_nik_item_id' => $this->request->get('gform-id-nik-kk'),
- 'gform_last_sync' => date('Y-m-d H:i:s'),
- 'config_id' => identitas('id'),
- ];
- $analisisMaster = AnalisisMaster::create($data_analisis_master);
- $id_master = $analisisMaster->id;
-
- // SIMPAN KATEGORI ANALISIS
- $list_kategori = $this->request->get('kategori');
- $temp_unique_kategori = [];
- $list_unique_kategori = [];
-
- // Get Unique Value dari Kategori
- foreach ($list_kategori as $key => $val) {
- if ($this->request->get('is_selected')[$key] != 'true') {
- continue;
- }
- if (in_array($val, $temp_unique_kategori)) {
- continue;
- }
- $temp_unique_kategori[] = $val;
- }
-
- // Simpan Unique Value dari Kategori
- foreach ($temp_unique_kategori as $key => $val) {
- $data_kategori = [
- 'id_master' => $id_master,
- 'kategori' => $val,
- 'kategori_kode' => '',
- 'config_id' => identitas('id'),
- ];
- $kategori = AnalisisKategori::create($data_kategori);
-
- $list_unique_kategori[$kategori->id] = $val;
- }
-
- // SIMPAN PERTANYAAN/INDIKATOR ANALISIS
- $id_column_nik_kk = $this->request->get('id-row-nik-kk');
- $count_indikator = 1;
- $db_idx_parameter = [];
- $db_idx_indikator = [];
-
- foreach ($this->request->get('pertanyaan') as $key => $val) {
- $temp_idx_parameter = [];
- $id_indikator = 0;
- if ($this->request->get('is_selected')[$key] == 'true' && $key != $id_column_nik_kk) {
- $data_indikator = [
- 'id_master' => $id_master,
- 'nomor' => $count_indikator,
- 'pertanyaan' => $val,
- 'id_tipe' => $this->request->get('tipe')[$key],
- 'bobot' => $this->request->get('bobot')[$key],
- 'act_analisis' => 0,
- 'id_kategori' => array_search($this->request->get('kategori')[$key], $list_unique_kategori, true),
- 'is_publik' => 0,
- 'is_teks' => 0,
- ];
-
- if ($data_indikator['id_tipe'] != 1) {
- $data_indikator['act_analisis'] = 2;
- $data_indikator['bobot'] = 0;
- }
-
- $data_indikator['config_id'] = identitas('id');
- $analisisIndikator = AnalisisIndikator::create($data_indikator);
- $id_indikator = $analisisIndikator->id;
-
- // Simpan Parameter untuk setiap unique value pada masing-masing indikator
- foreach ($this->request->get('unique-param-value-' . $key) as $param_key => $param_val) {
- $param_nilai = ($this->request->get('unique-param-nilai-' . $key)[$param_key] == '') ? 0 : $this->request->get('unique-param-nilai-' . $key)[$param_key];
-
- $data_parameter = [
- 'id_indikator' => $id_indikator,
- 'jawaban' => $this->request->get('unique-param-value-' . $key)[$param_key],
- 'nilai' => $param_nilai,
- 'kode_jawaban' => ($param_key + 1),
- 'asign' => 0,
- 'config_id' => identitas('id'),
- ];
- $analisisParameter = AnalisisParameter::create($data_parameter);
- $id_parameter = $analisisParameter->id;
- $temp_idx_parameter[$id_parameter] = $param_val;
- }
-
- $count_indikator++;
- }
- $db_idx_indikator[$id_indikator] = $key;
- $db_idx_parameter[] = $temp_idx_parameter;
- }
-
- // SIMPAN PERIODE ANALISIS
- $data_periode = [
- 'id_master' => $id_master,
- 'nama' => 'Pendataan ' . date('dmY_His'),
- 'id_state' => 1,
- 'aktif' => 1,
- 'keterangan' => 0,
- 'tahun_pelaksanaan' => $this->request->get('tahun_pendataan') == '' ? date('Y') : $this->request->get('tahun_pendataan'),
- 'config_id' => identitas('id'),
- ];
- $analisisPeriode = AnalisisPeriode::create($data_periode);
- $id_periode = $analisisPeriode->id;
-
- // SIMPAN RESPON ANALISIS
- $data_import = session('data_import');
-
- // Iterasi untuk setiap subjek
- foreach ($data_import['jawaban'] as $key_jawaban => $val_jawaban) {
- // Get Id Subjek berdasarkan Tipe Subjek (Penduduk / Keluarga / Rumah Tangga / Kelompok)
- $nik_kk_subject = $val_jawaban[$id_column_nik_kk];
- if ($data_analisis_master['subjek_tipe'] == AnalisisRefSubjekEnum::KELUARGA) {
- $id_subject = Keluarga::where(['no_kk' => $nik_kk_subject])->first()?->id;
- } else {
- $id_subject = Penduduk::where(['nik' => $nik_kk_subject])->first()?->id;
- }
-
- if ($id_subject != null && $id_subject != '') {
- // Iterasi untuk setiap indikator / jawaban dari subjek
- foreach ($this->request->get('pertanyaan') as $key_pertanyaan => $val_pertanyaan) {
- if ($this->request->get('is_selected')[$key_pertanyaan] == 'true' && $key_pertanyaan != $id_column_nik_kk) {
- $data_respon = [
- 'id_indikator' => array_search($key_pertanyaan, $db_idx_indikator, true),
- 'id_parameter' => array_search($val_jawaban[$key_pertanyaan], $db_idx_parameter[$key_pertanyaan], true),
- 'id_subjek' => $id_subject,
- 'id_periode' => $id_periode,
- ];
-
- AnalisisRespon::create($data_respon);
- }
- }
- } else {
- $list_error[] = 'NIK / No. KK data ke-' . ($key_jawaban + 1) . ' (' . $nik_kk_subject . ') ' . $id_subject . ' tidak valid';
- }
- }
-
- return ['error' => $list_error];
- }
-
- protected function getOAuthCredentialsFile()
- {
- // Hanya ambil dari config jika tidak ada setting aplikasi utk redirect_uri
- $api_gform_credential = setting('api_gform_credential') ?? config_item('api_gform_credential');
-
- return json_decode(str_replace('\"', '"', $api_gform_credential), true);
- }
-
- public function import_gform($redirect_link = '')
- {
- // Check Credential File
- if (! $oauth_credentials = $this->getOAuthCredentialsFile()) {
- echo 'ERROR - File Credential Not Found';
-
- return;
- }
-
- $redirect_uri = 'https://' . $_SERVER['HTTP_HOST'] . $_SERVER['PHP_SELF'];
-
- // Get the API client and construct the service object.
- $client = new Client();
- $client->setAuthConfig($oauth_credentials);
- $client->setRedirectUri($redirect_uri);
- $client->addScope('https://www.googleapis.com/auth/forms');
- $client->addScope('https://www.googleapis.com/auth/spreadsheets');
- $service = new Script($client);
-
- // API script id
- // Hanya ambil dari config jika tidak ada setting aplikasi unrtuk redirect_uri
- if (empty(setting('api_gform_id_script')) && empty(setting('api_gform_redirect_uri'))) {
- $script_id = config_item('api_gform_script_id');
- } else {
- $script_id = setting('api_gform_id_script');
- }
- // add "?logout" to the URL to remove a token from the session
- if (isset($_REQUEST['logout'])) {
- unset($_SESSION['upload_token']);
- }
-
- if (isset($_GET['code'])) {
- $token = $client->fetchAccessTokenWithAuthCode($_GET['code']);
- $client->setAccessToken($token);
-
- // store in the session also
- $_SESSION['upload_token'] = $token;
- }
-
- // set the access token as part of the client
- if (! empty($_SESSION['upload_token'])) {
- $client->setAccessToken($_SESSION['upload_token']);
- if ($client->isAccessTokenExpired()) {
- unset($_SESSION['upload_token']);
- }
- } else {
- $authUrl = $client->createAuthUrl();
- }
-
- // Create an execution request object.
- $request = new ExecutionRequest();
- $request->setFunction('getFormItems');
- $form_id = session('google_form_id');
- if ($form_id == '') {
- $form_id = session('gform_id');
- }
- $request->setParameters($form_id);
-
- try {
- if (isset($authUrl) && $_SESSION['inside_retry'] != true) {
- // If no authentication before
- set_session('form_id', $form_id);
- set_session('inside_retry', true);
- set_session('inside_redirect_link', $redirect_link);
- header('Location: ' . $authUrl);
- } else {
- // If it has authenticated
- // Make the API request.
- $response = $service->scripts->run($script_id, $request);
-
- if ($response->getError()) {
- echo 'Error';
- // The API executed, but the script returned an error.
-
- // Extract the first (and only) set of error details. The values of this
- // object are the script's 'errorMessage' and 'errorType', and an array of
- // stack trace elements.
- $error = $response->getError()['details'][0];
- printf("Script error message: %s\n", $error['errorMessage']);
-
- if (array_key_exists('scriptStackTraceElements', $error)) {
- // There may not be a stacktrace if the script didn't start executing.
- echo "Script error stacktrace:\n";
-
- foreach ($error['scriptStackTraceElements'] as $trace) {
- printf("\t%s: %d\n", $trace['function'], $trace['lineNumber']);
- }
- }
- } else {
- // Get Response
- $resp = $response->getResponse();
-
- return $resp['result'];
- }
- }
- } catch (Exception $e) {
- // The API encountered a problem before the script started executing.
- echo 'Caught exception: ', $e->getMessage(), "\n";
- }
-
- return '0';
- }
-
- public function update($id, $variabel)
- {
- // Get data analisis master
- $master_data = AnalisisMaster::find($id)->toArray();
-
- // Get existing data indikator (pertanyaan) dan parameter (jawaban)
- $existing_data = AnalisisIndikator::where(['id_master' => $id])->get()?->toArray();
-
- // Get existing respon
- $id_periode_aktif = AnalisisPeriode::active()->where(['id_master' => $id])->first()->toArray();
- $existing_respon = $this->get_respon_by_id_periode($id_periode_aktif, $master_data['subjek_tipe']);
-
- $id_column_nik_kk = 0;
- $list_error = [];
- $list_pertanyaan = [];
-
- $deleted_responden = [];
- $deleted_jawaban = [];
-
- foreach ($variabel['pertanyaan'] as $key_pertanyaan => $val_pertanyaan) {
- // Mencari kolom NIK/No. KK pada form
- if ($val_pertanyaan['itemId'] == $master_data['gform_nik_item_id']) {
- $id_column_nik_kk = $key_pertanyaan;
- }
- }
-
- // Cek keberadaan existing indikator pada data terkini, jika SALAH SATU SAJA hilang maka proses tidak dapat dilanjutkan
- foreach ($existing_data['indikator'] as $key_indikator => $val_indikator) {
- if (! array_search($val_indikator, array_column($variabel['pertanyaan'], 'title'), true)) {
- $list_error[] = 'Terdapat kolom yang hilang pada hasil response Google Form terkini (' . $val_indikator . ')';
- }
- }
-
- if ($list_error) {
-
- return ['error' => $list_error];
- }
-
- // Mencari nilai untuk pertanyaan-pertanyaan yang dimasukkan sebelumnya
- foreach ($existing_data['indikator'] as $key_indikator => $val_indikator) {
- foreach ($variabel['pertanyaan'] as $val_pertanyaan) {
- if ($val_indikator == $val_pertanyaan['title']) {
- // Mengisi nilai
- $list_pertanyaan[$key_indikator] = $val_pertanyaan;
-
- // Cek jawaban yang tidak terpakai
- $deleted_jawaban[$key_indikator] = $existing_data['parameter'][$key_indikator];
-
- foreach ($existing_data['parameter'][$key_indikator] as $key_param => $val_param) {
- if (array_search($val_param, $val_pertanyaan['choices'], true)) {
- unset($deleted_jawaban[$key_indikator][$key_param]);
- }
- }
-
- $new_parameter = [];
-
- // Insert jawaban baru
- foreach ($val_pertanyaan['choices'] as $val_choice) {
- // Jika nilai belum ada di database, maka tambahkan data parameter baru
- if (! (array_search($val_choice, $existing_data['parameter'][$key_indikator], true))) {
- $data_parameter = [
- 'id_indikator' => $key_indikator,
- 'jawaban' => $val_choice,
- 'nilai' => 0,
- 'kode_jawaban' => 0,
- 'asign' => 0,
- 'config_id' => identitas('id'),
- ];
- $analisisParameter = AnalisisParameter::create($data_parameter);
- $id_parameter = $analisisParameter->id;
- $data_parameter['id'] = $id_parameter;
- $new_parameter[$id_parameter] = $val_choice;
- }
- }
-
- // Update list parameter dengan operasi Union antara parameter yang sudah ada dengan parameter yang baru ditambahkan
- $existing_data['parameter'][$key_indikator] += $new_parameter;
-
- break;
- }
- }
- }
-
- foreach ($existing_respon as $key_respon => $val_respon) {
- if (! in_array($key_respon, array_column($variabel['jawaban'], $id_column_nik_kk), true)) {
- $deleted_responden[$key_respon] = $val_respon;
- }
- }
-
- foreach ($variabel['jawaban'] as $key_responden => $val_responden) {
- $nik_kk = $val_responden[$id_column_nik_kk];
-
- if ($master_data['subjek_tipe'] == AnalisisRefSubjekEnum::KELUARGA) {
- $id_subject = Keluarga::where(['no_kk' => $nik_kk])->first()?->id;
- } else {
- $id_subject = Penduduk::where(['no_kk' => $nik_kk])->first()?->id;
- }
-
- if ($id_subject != null && $id_subject != '') { // Jika NIK valid
- foreach ($val_responden as $key_jawaban => $val_jawaban) {
- $id_indikator = array_search($variabel['pertanyaan'][$key_jawaban], $list_pertanyaan, true); // Cek apakah kolom yang telah ada
-
- if ($id_indikator) {
- $id_parameter = array_search($val_jawaban, $existing_data['parameter'][$id_indikator], true); // Jawaban terkini
-
- if (isset($existing_respon[$val_responden[$id_column_nik_kk]])) {
- // Jika Responden sudah pernah disimpan
- $obj_respon = $existing_respon[$nik_kk][$id_indikator];
-
- if ($obj_respon['id_parameter'] != $id_parameter) {
- $where = [
- 'id_indikator' => $id_indikator,
- 'id_subjek' => $obj_respon['id_subjek'],
- 'id_periode' => $obj_respon['id_periode'],
- ];
- AnalisisRespon::where($where)->delete();
-
- $data_respon = [
- 'id_indikator' => $id_indikator,
- 'id_parameter' => $id_parameter,
- 'id_subjek' => $obj_respon['id_subjek'],
- 'id_periode' => $obj_respon['id_periode'],
- ];
- AnalisisRespon::create($data_respon);
- }
- } else {
- // Jika Responden belum pernah disimpan (Responden Baru)
- $data_respon = [
- 'id_indikator' => $id_indikator,
- 'id_parameter' => $id_parameter,
- 'id_subjek' => $id_subject,
- 'id_periode' => $id_periode_aktif,
- ];
-
- AnalisisRespon::create($data_respon);
- }
- }
- }
- } else {
- $list_error[] = 'NIK / No. KK data ke-' . ($key_responden + 1) . ' (' . $nik_kk . ') tidak valid';
- }
- }
-
- // Hapus data responden yang tidak ada di response terkini
- foreach (array_keys($deleted_responden) as $key_responden) {
- if ($master_data['subjek_tipe'] == AnalisisRefSubjekEnum::KELUARGA) {
- $id_subject = Keluarga::where(['no_kk' => $nik_kk])->first()?->id;
- } else {
- $id_subject = Penduduk::where(['no_kk' => $nik_kk])->first()?->id;
- }
-
- $where = [
- 'id_subjek' => $id_subject,
- 'id_periode' => $id_periode_aktif,
- ];
- AnalisisRespon::where($where)->delete();
- }
-
- // Update gform_last_sync
- $update_data = [
- 'gform_last_sync' => date('Y-m-d H:i:s'),
- ];
-
- AnalisisMaster::where('id', $id)->update($update_data);
-
- return ['error' => $list_error];
- }
-
- public function get_respon_by_id_periode($id_periode = 0, $subjek = 1)
- {
- $result = [];
- if ($subjek == 1) { // Untuk Subjek Penduduk
- $list_penduduk = AnalisisRespon::selectRaw('analisis_respon.*, tweb_penduduk.nik')->join('tweb_penduduk', 'tweb_penduduk.id', 'analisis_respon.id_subjek')->where(['id_periode' => $id_periode])->get()?->toArray();
-
- foreach ($list_penduduk as $penduduk) {
- $result[$penduduk['nik']][$penduduk['id_indikator']] = $penduduk;
- }
- } else { // Untuk Subjek Keluarga
- $list_keluarga = AnalisisRespon::selectRaw('analisis_respon.*, tweb_keluarga.no_kkk')->join('tweb_keluarga', 'tweb_keluarga.id', 'analisis_respon.id_subjek')->where(['id_periode' => $id_periode])->get()?->toArray();
-
- foreach ($list_keluarga as $keluarga) {
- $result[$keluarga['no_kk']][$keluarga['id_indikator']] = $keluarga;
- }
- }
-
- return $result;
- }
-}
+file = $file;
- }
-
- public function analisis($kode = '00000', $jenis = 2): void
- {
- $reader = new Reader();
- $reader->open($this->file);
- $id_master = null;
-
- foreach ($reader->getSheetIterator() as $sheet) {
- switch ($sheet->getName()) {
- case 'master':
- $id_master = $this->impor_master($sheet, $kode, $jenis);
- break;
-
- case 'pertanyaan':
- $this->impor_pertanyaan($sheet, $id_master);
- break;
-
- case 'jawaban':
- $this->impor_jawaban($sheet, $id_master);
- break;
-
- case 'klasifikasi':
- $this->impor_klasifikasi($sheet, $id_master);
- break;
-
- default:
- }
- }
- $reader->close();
- }
-
- private function impor_master($sheet, $kode, $jenis)
- {
- $master = [];
-
- foreach ($sheet->getRowIterator() as $index => $row) {
- $cells = $row->getCells();
-
- switch ($index) {
- case 1: // Nama analisis
- $master['nama'] = $cells[1]->getValue();
- break;
-
- case 2: // Subjek
- $master['subjek_tipe'] = $cells[1]->getValue();
- break;
-
- case 3: // Status
- $master['lock'] = $cells[1]->getValue();
- break;
-
- case 4: // Bilangan Pembagi
- $master['pembagi'] = $cells[1]->getValue();
- break;
-
- case 5: // Deskripsi Analisis
- $master['deskripsi'] = $cells[1]->getValue();
- $periode['keterangan'] = $cells[1]->getValue();
- break;
-
- case 6: // Nama Periode
- $periode['nama'] = $cells[1]->getValue();
- break;
-
- case 7: // Tahun Pendataan
- $periode['tahun_pelaksanaan'] = $cells[1]->getValue();
- break;
- }
- }
- $master['kode_analisis'] = $kode;
- $master['jenis'] = $jenis;
- $master['config_id'] = identitas('id');
-
- $analisisMaster = AnalisisMaster::create($master);
-
- $periode['id_master'] = $analisisMaster->id;
- $periode['aktif'] = 1;
- $periode['config_id'] = identitas('id');
-
- AnalisisPeriode::create($periode);
-
- return $analisisMaster->id;
- }
-
- private function impor_pertanyaan($sheet, $id_master)
- {
- foreach ($sheet->getRowIterator() as $index => $row) {
- if ($index == 1) {
- continue;
- } // Abaikan baris judul
- $cells = $row->getCells();
- // Tambahkan indikator
- $indikator = [];
- $indikator['id_master'] = $id_master;
- $indikator['nomor'] = $cells[0]->getValue();
- $indikator['pertanyaan'] = $cells[1]->getValue();
- $indikator['id_kategori'] = $this->get_id_kategori($cells[2]->getValue(), $id_master);
- $indikator['id_tipe'] = $cells[3]->getValue();
- $indikator['config_id'] = identitas('id');
- if (! empty($cells[4]) && $cells[4]->getValue()) {
- $indikator['bobot'] = (int) $cells[4]->getValue();
- }
- if (! empty($cells[5]) && $cells[5]->getValue()) {
- $indikator['act_analisis'] = $cells[5]->getValue();
- }
-
- AnalisisIndikator::create($indikator);
- }
- }
-
- private function get_id_kategori($kategori, $id_master)
- {
- $adaKategori = AnalisisKategori::firstOrCreate(['kategori' => $kategori, 'id_master' => $id_master]);
-
- return $adaKategori->id;
- }
-
- private function impor_jawaban($sheet, $id_master)
- {
- foreach ($sheet->getRowIterator() as $index => $row) {
- if ($index == 1) {
- continue;
- } // Abaikan baris judul
- $cells = $row->getCells();
- // Tambahkan parameter
- $parameter = [];
- $parameter['id_indikator'] = $this->get_id_indikator($cells[0]->getValue(), $id_master);
- $parameter['jawaban'] = $cells[2]->getValue();
- $parameter['config_id'] = identitas('id');
- if (! empty($cells[1]) && $cells[1]->getValue()) {
- $parameter['kode_jawaban'] = $cells[1]->getValue();
- }
- if (! empty($cells[3]) && $cells[3]->getValue()) {
- $parameter['nilai'] = $cells[3]->getValue();
- }
- AnalisisParameter::create($parameter);
- }
- }
-
- private function get_id_indikator($kode_pertanyaan, $id_master)
- {
- return AnalisisIndikator::where(['id_master' => $id_master, 'nomor' => $kode_pertanyaan])->first()?->id;
- }
-
- private function impor_klasifikasi($sheet, $id_master)
- {
- foreach ($sheet->getRowIterator() as $index => $row) {
- if ($index == 1) {
- continue;
- } // Abaikan baris judul
- $cells = $row->getCells();
- // Tambahkan parameter
- $klasifikasi = [];
- $klasifikasi['id_master'] = $id_master;
- $klasifikasi['nama'] = $cells[0]->getValue();
- $klasifikasi['minval'] = $cells[1]->getValue();
- $klasifikasi['maxval'] = $cells[2]->getValue();
- $klasifikasi['config_id'] = identitas('id');
-
- AnalisisKlasifikasi::create($klasifikasi);
- }
- }
-}
+belongsTo(AnalisisKategori::class, 'id_kategori');
- }
-
- /**
- * Get all of the parameter for the AnalisisIndikator
- */
- public function parameter(): HasMany
- {
- return $this->hasMany(AnalisisParameter::class, 'id_indikator');
- }
-
- public static function hubungan($sasaran)
- {
- switch ($sasaran) {
-
- // Penduduk
- case 1:
- $data = [
- 'kk_level' => [
- 'judul' => 'Hubungan Dalam Keluarga',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_hubungan'),
- ],
- 'rtm_level' => [
- 'judul' => 'Hubungan Dalam Rumah Tangga',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_rtm_hubungan'),
- ],
- 'sex' => [
- 'judul' => 'Jenis Kelamin',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_sex'),
- ],
- 'tempatlahir' => [
- 'judul' => 'Tempat Lahir',
- ],
- 'tanggallahir' => [
- 'judul' => 'Tanggal Lahir',
- ],
- 'agama_id' => [
- 'judul' => 'Agama',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_agama'),
- ],
- 'pendidikan_kk_id' => [
- 'judul' => 'Pendidikan Dalam KK',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_pendidikan_kk'),
- ],
- 'pendidikan_sedang_id' => [
- 'judul' => 'Pendidikan Sedang Ditempuh',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_pendidikan'),
- ],
- 'pekerjaan_id' => [
- 'judul' => 'Pekerjaan',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_pekerjaan'),
- ],
- 'status_kawin' => [
- 'judul' => 'Status_perkawinan',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_kawin'),
- ],
- 'warganegara_id' => [
- 'judul' => 'Kewarganegaraan',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_warganegara'),
- ],
- 'dokumen_pasport' => [
- 'judul' => 'Dokumen Passport',
- ],
- 'dokumen_kitas' => [
- 'judul' => 'Dokumen KITAS',
- ],
- 'ayah_nik' => [
- 'judul' => 'NIK Ayah',
- ],
- 'nama_ayah' => [
- 'judul' => 'Nama Ayah',
- ],
- 'ibu_nik' => [
- 'judul' => 'NIK Ibu',
- ],
- 'nama_ibu' => [
- 'judul' => 'Nama Ibu',
- ],
- 'golongan_darah_id' => [
- 'judul' => 'Golongan Darah',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_golongan_darah'),
- ],
- // id_cluster => wilayah, agar tdk duplikasi
- 'wilayah' => [
- 'judul' => 'Wilayah (Dusun/RW/RT)',
- ],
- 'status' => [
- 'judul' => 'Status Penduduk',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_status'),
- ],
- 'alamat_sebelumnya' => [
- 'judul' => 'Alamat Sebelumnya',
- ],
- 'alamat_sekarang' => [
- 'judul' => 'Alamat Sekarang',
- ],
- 'status_dasar' => [
- 'judul' => 'Status Dasar',
- // 'referensi' => $this->referensi_model->list_data('tweb_status_dasar'),
- ],
- 'hamil' => [
- 'judul' => 'Status Kehamilan',
- ],
- 'cacat_id' => [
- 'judul' => 'Jenis Cacat',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_cacat'),
- ],
- 'sakit_menahun_id' => [
- 'judul' => 'Sakit Menahun',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_sakit_menahun'),
- ],
- 'akta_lahir' => [
- 'judul' => 'Akta Lahir',
- ],
- 'akta_perkawinan' => [
- 'judul' => 'Akta Perkawinan',
- ],
- 'tanggalperkawinan' => [
- 'judul' => 'Tanggal Perkawinan',
- ],
- 'akta_perceraian' => [
- 'judul' => 'Akta Perceraian',
- ],
- 'tanggalperceraian' => [
- 'judul' => 'Tanggal Perceraian',
- ],
- 'cara_kb_id' => [
- 'judul' => 'Akseptor KB',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_cara_kb'),
- ],
- 'telepon' => [
- 'judul' => 'Telepon',
- ],
- 'tanggal_akhir_paspor' => [
- 'judul' => 'Tanggal Akhir Paspor',
- ],
- 'no_kk_sebelumnya' => [
- 'judul' => 'No. KK Sebelumnya',
- ],
- 'ktp_el' => [
- 'judul' => 'E-KTP',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_status_ktp'),
- ],
- 'status_rekam' => [
- 'judul' => 'Status Rekam',
- // 'referensi' => $this->referensi_model->list_status_rekam(),
- ],
- 'waktu_lahir' => [
- 'judul' => 'Waktu Lahir',
- ],
- 'tempat_dilahirkan' => [
- 'judul' => 'Tempat Dilahirkan',
- ],
- 'jenis_kelahiran' => [
- 'judul' => 'Jenis Kelahiran',
- ],
- 'kelahiran_anak_ke' => [
- 'judul' => 'Kelahiran Anak Ke - ',
- 'tipe' => 3,
- ],
- 'penolong_kelahiran' => [
- 'judul' => 'Penolong Kelahiran',
- ],
- 'berat_lahir' => [
- 'judul' => 'Berat lahir',
- 'tipe' => 3,
- ],
- 'panjang_lahir' => [
- 'judul' => 'Panjang Lahir',
- 'tipe' => 3,
- ],
- 'tag_id_card' => [
- 'judul' => 'Tag ID Card',
- ],
- 'id_asuransi' => [
- 'judul' => 'ID Asuransi',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_asuransi'),
- ],
- 'no_asuransi' => [
- 'judul' => 'No. Asusransi',
- ],
- 'email' => [
- 'judul' => 'Email',
- ],
- 'bahasa_id' => [
- 'judul' => 'Dapat Membaca Huruf',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('ref_penduduk_bahasa'),
- ],
- 'negara_asal' => [
- 'judul' => 'Negara Asal',
- ],
- 'tempat_cetak_ktp' => [
- 'judul' => 'Tempat Cetak KTP',
- ],
- 'tanggal_cetak_ktp' => [
- 'judul' => 'Tanggal Cetak KTP',
- ],
- 'suku' => [
- 'judul' => 'Suku/Etnis',
- ],
- 'bpjs_ketenagakerjaan' => [
- 'judul' => 'BPJS Ketenagakerjaan',
- ],
- ];
- break;
-
- // Keluarga
- case 2:
- $data = [
- 'nik_kepala' => [
- 'judul' => 'NIK Kepala KK',
- ],
- 'kelas_sosial' => [
- 'judul' => 'Kelas Sosial',
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_keluarga_sejahtera'),
- ],
- 'alamat' => [
- 'judul' => 'Alamat',
- ],
- // id_cluster => wilayah, agar tdk duplikasi
- 'wilayah' => [
- 'judul' => 'Wilayah (Dusun/RW/RT)',
- ],
- ];
- break;
-
- // Desa
- default:
-
- $desa = setting('sebutan_desa');
- $kepala = setting('sebutan_kepala_desa');
-
- $data = [
-
- // IDENTITAS DESA
- 'nama_desa' => [
- 'judul' => 'Nama ' . $desa,
- ],
- 'kode_desa' => [
- 'judul' => 'Kode ' . $desa,
- ],
- 'kode_pos' => [
- 'judul' => 'Kode POS',
- ],
- 'nama_kepala_desa' => [
- 'judul' => 'Nama ' . $kepala,
- ],
- 'nip_kepala_desa' => [
- 'judul' => 'NIP ' . $kepala,
- ],
- 'jk_kepala_desa' => [
- 'judul' => 'Jenis Kelamin ' . $kepala,
- 'tipe' => 1,
- // 'referensi' => $this->referensi_model->list_data('tweb_penduduk_sex'),
- ],
- 'titik_koordinat_desa' => [
- 'judul' => 'Titik Koordinat ' . $desa . ' (Lintang / Bujur)',
- ],
- 'alamat_kantor' => [
- 'judul' => 'Alamat Kantor',
- ],
- 'no_telepon_kepala_desa' => [
- 'judul' => 'Nomor Telepon Rumah / HP ' . $kepala,
- ],
- 'no_telepon_kantor_desa' => [
- 'judul' => 'Nomor Telepon Kantor ' . $desa,
- ],
- 'email_desa' => [
- 'judul' => 'Email ' . $desa,
- ],
- 'pendidikan_kepala_desa' => [
- 'judul' => 'Pendidikan Terakhir ' . $kepala,
- ],
- 'nama_kecamatan' => [
- 'judul' => 'Nama Kecamatan',
- ],
- 'kode_kecamatan' => [
- 'judul' => 'Kode Kecamatan',
- ],
- 'nama_kepala_camat' => [
- 'judul' => 'Nama Kepala Camat',
- ],
- 'nip_kepala_camat' => [
- 'judul' => 'NIP Kepala Camat',
- ],
- 'kode_kabupaten' => [
- 'judul' => 'Kode Kabupaten',
- ],
- 'nama_propinsi' => [
- 'judul' => 'Nama Provinsi',
- ],
- 'kode_propinsi' => [
- 'judul' => 'Kode Provinsi',
- ],
-
- // DEMOGRAFI
- // # Penduduk
- 'jumlah_total_penduduk' => [
- 'judul' => 'Jumlah Total Penduduk',
- ],
- 'jumlah_penduduk_laki_laki' => [
- 'judul' => 'Jumlah Penduduk Laki-laki',
- ],
- 'jumlah_penduduk_perempuan' => [
- 'judul' => 'Jumlah Penduduk Perempuan',
- ],
- 'jumlah_penduduk_pedatang' => [
- 'judul' => 'Jumlah Penduduk Pendatang',
- ],
- 'jumlah_penduduk_yang_pergi' => [
- 'judul' => 'Jumlah Penduduk Yang Pergi',
- ],
-
- // # Kepala Keluarga
- 'jumlah_total_kepala_keluarga' => [
- 'judul' => 'Jumlah Total Kepala Keluarga',
- ],
- 'jumlah_kepala_keluarga_laki_laki' => [
- 'judul' => 'Jumlah Kepala Keluarga Laki-laki',
- ],
- 'jumlah_kepala_keluarga_perempuan' => [
- 'judul' => 'Jumlah Kepala Keluarga Perempuan',
- ],
-
- 'jumlah_peserta_bpjs' => [
- 'judul' => 'Jumlah Penduduk Terdaftar BPJS Kesehatan / JKN',
- ],
- ];
- break;
- }
-
- return $data;
- }
-
- public static function indikatorUnduh($idMaster, $parameter = 1)
- {
- $data = self::where('id_master', $idMaster)->orderByRaw('LPAD(nomor, 10, " ")')->get()->toArray();
- $counter = count($data);
-
- for ($i = 0; $i < $counter; $i++) {
- $data[$i]['no'] = $i + 1;
- $data[$i]['par'] = null;
-
- if ($parameter == 2) {
- $par = AnalisisParameter::where('id_indikator', $data[$i]['id'])->where('asign', 1)->get()->toArray();
- $data[$i]['par'] = $par;
- }
- }
-
- return $data;
- }
-}
+hasMany(AnalisisIndikator::class, 'id_kategori');
- }
-}
+attributes['lock'] == self::LOCK;
- }
-
- public function isSystem(): bool
- {
- return $this->attributes['jenis'] == 1;
- }
-
- protected function scopeSubjekPenduduk($query)
- {
- return $query->where('subjek_tipe', AnalisisRefSubjekEnum::PENDUDUK);
- }
-}
+belongsTo(AnalisisIndikator::class, 'id_indikator');
- }
-}
+id_state];
- }
-
- public function isLock(): bool
- {
- return $this->attributes['aktif'] == self::LOCK;
- }
-
- public function isUnlock(): bool
- {
- return $this->attributes['aktif'] == self::UNLOCK;
- }
-
- public function scopeActive($query)
- {
- return $query->where('aktif', self::UNLOCK);
- }
-}
+where('id_periode', $idPeriode)->delete();
- if (! empty($postData['rb'])) {
- $id_rb = $postData['rb'];
-
- foreach ($id_rb as $id_p) {
- if (empty($id_p)) {
- continue;
- } // Abaikan isian kosong
- $p = preg_split('/\\./', $id_p);
-
- $data['id_subjek'] = $id;
- $data['id_periode'] = $idPeriode;
- $data['id_indikator'] = $p[0];
- $data['id_parameter'] = $p[1];
- self::insert($data);
- }
- }
- if (isset($postData['cb'])) {
- $id_cb = $postData['cb'];
- if ($id_cb) {
- foreach ($id_cb as $id_p) {
- $p = preg_split('/\\./', $id_p);
-
- $data['id_subjek'] = $id;
- $data['id_periode'] = $idPeriode;
- $data['id_indikator'] = $p[0];
- $data['id_parameter'] = $p[1];
- self::insert($data);
- }
- }
- }
-
- if (isset($postData['ia'])) {
- $id_ia = $postData['ia'];
-
- foreach ($id_ia as $id_p) {
- if ($id_p != '') {
- unset($data);
- $indikator = key($id_ia);
- $dx = AnalisisParameter::firstOrCreate(['jawaban' => $id_p, 'id_indikator' => $indikator]);
-
- unset($data);
- $data['id_parameter'] = $dx->id;
- $data['id_indikator'] = $indikator;
- $data['id_subjek'] = $id;
- $data['id_periode'] = $idPeriode;
- self::create($data);
- }
- next($id_ia);
- }
- }
- if (isset($postData['it'])) {
- $id_it = $postData['it'];
-
- foreach ($id_it as $id_p) {
- if ($id_p != '') {
- unset($data);
- $indikator = key($id_it);
- $dx = AnalisisParameter::firstOrCreate(['jawaban' => $id_p, 'id_indikator' => $indikator]);
-
- $data2['id_parameter'] = $dx->id;
- $data2['id_indikator'] = $indikator;
- $data2['id_subjek'] = $id;
- $data2['id_periode'] = $idPeriode;
- self::create($data2);
- }
- next($id_it);
- }
- }
-
- $sql = 'SELECT SUM(i.bobot * nilai) as jml FROM analisis_respon r LEFT JOIN analisis_indikator i ON r.id_indikator = i.id LEFT JOIN analisis_parameter z ON r.id_parameter = z.id WHERE r.id_subjek = ? AND i.act_analisis=1 AND r.id_periode=? ';
- $dx = (array) DB::select($sql, [$id, $idPeriode])[0];
-
- $upx['id_master'] = $idMaster;
- $upx['akumulasi'] = 0 + $dx['jml'];
- $upx['id_subjek'] = $id;
- $upx['id_periode'] = $idPeriode;
- $upx['config_id'] = identitas('id');
- AnalisisResponHasil::where('id_subjek', $id)->where('id_periode', $idPeriode)->delete();
- AnalisisResponHasil::create($upx);
- }
- }
-
- public function import_respon($idMaster, $periode, $subjekTipe, $op = 0)
- {
- $per = $periode;
- $subjek = $subjekTipe;
- $mas = $idMaster;
- $key = ($per + 3) * ($mas + 7) * ($subjek * 3);
- $key = 'AN' . $key;
- $respon = [];
-
- $indikator = AnalisisIndikator::where('id_master', $idMaster)->orderBy('id')->get()->toArray();
-
- try {
- if ($_FILES['respon']['type'] != 'application/vnd.ms-excel') {
- return [
- 'success' => false,
- 'message' => 'File yang diunggah harus berformat .xls',
- ];
- }
- $data = new Spreadsheet_Excel_Reader($_FILES['respon']['tmp_name']);
- $s = 0;
- $baris = $data->rowcount($s);
- $kolom = $data->colcount($s);
-
- $ketemu = 0;
-
- for ($b = 1; $b <= $baris; $b++) {
- for ($k = 1; $k <= $kolom; $k++) {
- $isi = $data->val($b, $k, $s);
- // ketemu njuk stop
- if ($isi == $key) {
- $br = $b + 1;
- $kl = $k + 1;
-
- $b = $baris + 1;
- $k = $kolom + 1;
- $ketemu = 1;
- }
- }
- }
- if ($ketemu == 1) {
- $dels = '';
- $true = 0;
-
- for ($i = $br; $i <= $baris; $i++) {
- $id_subjek = $data->val($i, $kl - 1, $s);
-
- $j = $kl;
-
- foreach ($indikator as $indi) {
- $isi = $data->val($i, $j, $s);
- if ($isi != '') {
- $true = 1;
- }
-
- $j++;
- }
- if ($true == 1) {
- $dels .= $id_subjek . ',';
- $true = 0;
- }
- }
-
- $dels .= '9999999';
- //cek ada row
- self::where('id_periode', $per)->whereRaw("id_subjek in({$dels})")->delete();
- $dels = '';
-
- for ($i = $br; $i <= $baris; $i++) {
- $id_subjek = $data->val($i, $kl - 1, $s);
- if (strlen($id_subjek) > 14 && $subjek == 1) {
- $id_subjek = PendudukHidup::select(['id'])->where('nik', $id_subjek)->first()?->id ?? null;
- } elseif ($subjek == 3) {
- // sasaran rumah tangga, simpan id, bukan nomor rumah tangga
- $id_subjek = Rtm::select('id')->where('id_rtm', $id_subjek)->first()?->id ?? null;
- }
-
- $j = $kl + $op;
- $all = '';
-
- foreach ($indikator as $indi) {
- $isi = $data->val($i, $j, $s);
- if ($isi != '') {
- if ($indi['id_tipe'] == 1) {
- $param = AnalisisParameter::where('id_indikator', $indi['id'])
- ->where(static function ($query) use ($isi) {
- $query->where('kode_jawaban', $isi)->orWhere('jawaban', $isi);
- })->first()->toArray();
- if ($param) {
- $in_param = $param['id'];
- } elseif ($isi == '') {
- $in_param = 0;
- } else {
- $in_param = -1;
- }
-
- $respon[] = [
- 'id_parameter' => $in_param,
- 'id_indikator' => $indi['id'],
- 'id_subjek' => $id_subjek,
- 'id_periode' => $per,
- ];
- } elseif ($indi['id_tipe'] == 2) {
- $this->respon_checkbox($indi, $isi, $id_subjek, $per, $respon);
- } else {
- $param = AnalisisParameter::where('id_indikator', $indi['id'])->where('jawaban', $isi)->first()->toArray();
-
- // apakah sdh ada jawaban yg sama
- if ($param) {
- $in_param = $param['id'];
- } else {
- $parameter['jawaban'] = $isi;
- $parameter['id_indikator'] = $indi['id'];
- $parameter['asign'] = 0;
- $parameter['config_id'] = identitas('id');
- AnalisisParameter::create($parameter);
-
- $param = AnalisisParameter::where('id_indikator', $indi['id'])->where('jawaban', $isi)->first()->toArray();
- $in_param = $param['id'];
- }
-
- $respon[] = [
- 'id_parameter' => $in_param,
- 'id_indikator' => $indi['id'],
- 'id_subjek' => $id_subjek,
- 'id_periode' => $per,
- ];
- }
- }
-
- $j++;
- }
- }
-
- if (count($respon) > 0) {
- AnalisisRespon::insert($respon);
- } else {
- return [
- 'success' => false,
- 'message' => 'Tidak ada data yang diimpor',
- ];
- }
- }
-
- $this->pre_update($idMaster, $per);
- } catch (Exception $e) {
- return [
- 'success' => false,
- 'pesan' => $e->getMessage(),
- ];
- }
-
- return [
- 'success' => true,
- 'message' => 'Data berhasil diimpor',
- ];
- }
-
- private function respon_checkbox($indi, $isi, $id_subjek, $per, &$respon): void
- {
- $list_isi = explode(',', $isi);
-
- foreach ($list_isi as $isi_ini) {
- if ($indi['is_teks'] == 1) {
- // Isian sebagai teks pilihan bukan kode
- $teks = strtolower($isi_ini);
- $param = AnalisisParameter::where('id_indikator', $indi['id'])->whereRaw("LOWER(jawaban) = '{$teks}'")->first()->toArray();
- } else {
- $param = AnalisisParameter::where('id_indikator', $indi['id'])->where('kode_jawaban', $isi_ini)->first()->toArray();
- }
- if ($param['id'] != '') {
- $in_param = $param['id'];
- $respon[] = [
- 'id_parameter' => $in_param,
- 'id_indikator' => $indi['id'],
- 'id_subjek' => $id_subjek,
- 'id_periode' => $per,
- 'config_id' => identitas('id'),
- ];
- }
- }
- }
-
- public function pre_update($idMaster, $per): void
- {
- $data = AnalisisRespon::selectRaw('distinct(id_subjek) as id')->where('id_periode', $per)->get()->toArray();
-
- AnalisisResponHasil::where('id_subjek', 0)->delete();
- AnalisisRespon::where('id_subjek', 0)->delete();
- AnalisisResponHasil::where('id_periode', $per)->delete();
-
- $counter = count($data);
-
- for ($i = 0; $i < $counter; $i++) {
- $sql = 'SELECT SUM(i.bobot * nilai) as jml FROM analisis_respon r LEFT JOIN analisis_indikator i ON r.id_indikator = i.id LEFT JOIN analisis_parameter z ON r.id_parameter = z.id WHERE r.id_subjek = ? AND i.act_analisis=1 AND r.id_periode=?';
- $dx = (array) DB::select($sql, [$data[$i]['id'], $per])[0];
-
- $upx[$i]['id_master'] = $idMaster;
- $upx[$i]['akumulasi'] = 0 + $dx['jml'];
- $upx[$i]['id_subjek'] = $data[$i]['id'];
- $upx[$i]['id_periode'] = $per;
- $upx[$i]['config_id'] = identitas('id');
- }
- if (@$upx) {
- AnalisisResponHasil::insert($upx);
- }
- }
-}
+active()->value('id');
- $data = self::where('id_periode', $per)->distinct()->pluck('id_subjek');
-
- self::where('id_subjek', 0)->delete();
- AnalisisRespon::where('id_subjek', 0)->delete();
- self::where('id_periode', $per)->delete();
-
- $upx = $data->map(static function ($id_subjek) use ($per, $idMaster) {
- $akumulasi = self::where('id_subjek', $id_subjek)
- ->where('id_periode', $per)
- ->whereHas('indikator', static fn ($query) => $query->where('act_analisis', 1))
- ->sum(DB::raw('analisis_indikator.bobot * nilai'));
-
- return [
- 'id_master' => $idMaster,
- 'akumulasi' => $akumulasi ?: 0,
- 'id_subjek' => $id_subjek,
- 'id_periode' => $per,
- ];
- })->toArray();
-
- if ($upx) {
- self::insert($upx);
- }
- }
-}
+registerViews();
+ }
+
+ /**
+ * Register the service provider.
+ *
+ * @return void
+ */
+ public function register()
{
- parent::__construct();
- if (! $this->session->is_anjungan) {
- redirect(route('layanan-mandiri.beranda.index'));
- }
}
- public function index()
+ /**
+ * Register views.
+ */
+ public function registerViews(): void
{
- $data['beranda'] = true;
+ $sourcePath = FCPATH . 'Modules' . DIRECTORY_SEPARATOR . $this->moduleName . DIRECTORY_SEPARATOR . 'Views';
- return view('anjungan.beranda.content', $data);
+ $this->loadViewsFrom($sourcePath, $this->moduleNameLower);
}
}
diff --git a/Modules/Analisis/Routes/web.php b/Modules/Analisis/Routes/web.php
index 766b1886e..2b932da98 100644
--- a/Modules/Analisis/Routes/web.php
+++ b/Modules/Analisis/Routes/web.php
@@ -1,148 +1,457 @@
- 'Analisis'], static function (): void {
- Route::get('', 'Analisis_master@index')->name('analisis_master.index-default');
- Route::get('clear', 'Analisis_master@index')->name('analisis_master.clear');
- Route::get('datatables', 'Analisis_master@datatables')->name('analisis_master.datatables');
- Route::get('form/{id?}', 'Analisis_master@form')->name('analisis_master.form');
- Route::post('insert', 'Analisis_master@insert')->name('analisis_master.insert');
- Route::post('update/{id?}', 'Analisis_master@update')->name('analisis_master.update');
- Route::get('delete/{id?}', 'Analisis_master@delete')->name('analisis_master.delete');
- Route::post('delete', 'Analisis_master@delete')->name('analisis_master.delete-all');
- Route::get('lock/{id}', 'Analisis_master@lock')->name('analisis_master.lock');
- Route::get('panduan', 'Analisis_master@panduan')->name('analisis_master.panduan');
- Route::get('import_analisis', 'Analisis_master@import_analisis')->name('analisis_master.import_analisis');
- Route::post('import', 'Analisis_master@import')->name('analisis_master.import');
- Route::get('ekspor/{id}', 'Analisis_master@ekspor')->name('analisis_master.ekspor');
- Route::get('import_gform/{id?}', 'Analisis_master@import_gform')->name('analisis_master.import_gform');
- Route::get('menu/{id?}', 'Analisis_master@menu')->name('analisis_master.menu');
- Route::post('exec_import_gform', 'Analisis_master@exec_import_gform')->name('analisis_master.exec_import_gform');
- Route::post('save_import_gform/{id?}', 'Analisis_master@save_import_gform')->name('analisis_master.save_import_gform');
- Route::match(['GET', 'POST'], '/update_gform/{id?}', 'Analisis_master@update_gform')->name('analisis_master.update_gform');
-});
-
-Route::group('analisis_indikator/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_indikator@index')->name('analisis_indikator.index-default');
- Route::get('datatables', 'Analisis_indikator@datatables')->name('analisis_indikator.datatables');
- Route::get('form/{id?}', 'Analisis_indikator@form')->name('analisis_indikator.form');
- Route::post('insert', 'Analisis_indikator@insert')->name('analisis_indikator.insert');
- Route::post('update/{id?}', 'Analisis_indikator@update')->name('analisis_indikator.update');
- Route::get('delete/{id?}', 'Analisis_indikator@delete')->name('analisis_indikator.delete');
- Route::post('delete', 'Analisis_indikator@delete')->name('analisis_indikator.delete-all');
- Route::group('parameter/{indikator}', static function (): void {
- Route::get('', 'Analisis_parameter@index')->name('analisis_parameter.index-default');
- Route::get('datatables', 'Analisis_parameter@datatables')->name('analisis_parameter.datatables');
- Route::get('form/{id?}', 'Analisis_parameter@form')->name('analisis_parameter.form');
- Route::post('insert', 'Analisis_parameter@insert')->name('analisis_parameter.insert');
- Route::post('update/{id?}', 'Analisis_parameter@update')->name('analisis_parameter.update');
- Route::get('delete/{id?}', 'Analisis_parameter@delete')->name('analisis_parameter.delete');
- Route::post('delete', 'Analisis_parameter@delete')->name('analisis_parameter.delete-all');
- });
-});
-
-Route::group('analisis_kategori/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_kategori@index')->name('analisis_kategori.index-default');
- Route::get('datatables', 'Analisis_kategori@datatables')->name('analisis_kategori.datatables');
- Route::get('form/{id?}', 'Analisis_kategori@form')->name('analisis_kategori.form');
- Route::post('insert', 'Analisis_kategori@insert')->name('analisis_kategori.insert');
- Route::post('update/{id?}', 'Analisis_kategori@update')->name('analisis_kategori.update');
- Route::get('delete/{id?}', 'Analisis_kategori@delete')->name('analisis_kategori.delete');
- Route::post('delete', 'Analisis_kategori@delete')->name('analisis_kategori.delete-all');
-});
-
-Route::group('analisis_klasifikasi/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_klasifikasi@index')->name('analisis_klasifikasi.index-default');
- Route::get('datatables', 'Analisis_klasifikasi@datatables')->name('analisis_klasifikasi.datatables');
- Route::get('form/{id?}', 'Analisis_klasifikasi@form')->name('analisis_klasifikasi.form');
- Route::post('insert', 'Analisis_klasifikasi@insert')->name('analisis_klasifikasi.insert');
- Route::post('update/{id?}', 'Analisis_klasifikasi@update')->name('analisis_klasifikasi.update');
- Route::get('delete/{id?}', 'Analisis_klasifikasi@delete')->name('analisis_klasifikasi.delete');
- Route::post('delete', 'Analisis_klasifikasi@delete')->name('analisis_klasifikasi.delete-all');
-});
-
-Route::group('analisis_respon/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_respon@index');
- Route::get('datatables', 'Analisis_respon@datatables')->name('analisis_respon.datatables');
- Route::get('form/{id}/{fs?}', 'Analisis_respon@form')->name('analisis_respon.form');
- Route::get('perbaharui/{id_subjek}', 'Analisis_respon@perbaharui')->name('analisis_respon.perbaharui');
- Route::post('update/{id}', 'Analisis_respon@update')->name('analisis_respon.update');
- Route::get('aturan_unduh', 'Analisis_respon@aturan_unduh')->name('analisis_respon.aturan_unduh');
- Route::get('data_ajax', 'Analisis_respon@data_ajax')->name('analisis_respon.data_ajax');
- Route::post('data_unduh', 'Analisis_respon@data_unduh')->name('analisis_respon.data_unduh');
- Route::get('import/{op?}', 'Analisis_respon@import')->name('analisis_respon.import');
- Route::post('import_proses/{op?}', 'Analisis_respon@import_proses')->name('analisis_respon.import_proses');
- Route::get('form_impor_bdt/{id?}', 'Analisis_respon@form_impor_bdt')->name('analisis_respon.form_impor_bdt');
- Route::post('impor_bdt', 'Analisis_respon@impor_bdt')->name('analisis_respon.impor_bdt');
- Route::group('child', static function (): void {
- Route::get('form/{id}/{idc?}', 'Analisis_respon_child@formChild')->name('analisis_respon.form_child');
- Route::post('update/{id}/{idc?}', 'Analisis_respon_child@updateChild')->name('analisis_respon.update_child');
- });
-});
-Route::group('analisis_periode/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_periode@index')->name('analisis_periode.index-default');
- Route::get('datatables', 'Analisis_periode@datatables')->name('analisis_periode.datatables');
- Route::get('form/{id?}', 'Analisis_periode@form')->name('analisis_periode.form');
- Route::post('insert', 'Analisis_periode@insert')->name('analisis_periode.insert');
- Route::post('update/{id?}', 'Analisis_periode@update')->name('analisis_periode.update');
- Route::get('lock/{id}', 'Analisis_periode@lock')->name('analisis_periode.lock');
- Route::get('delete/{id?}', 'Analisis_periode@delete')->name('analisis_periode.delete');
- Route::post('delete', 'Analisis_periode@delete')->name('analisis_periode.delete-all');
-});
-
-Route::group('analisis_laporan/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_laporan@index');
- Route::get('datatables', 'Analisis_laporan@datatables')->name('analisis_laporan.datatables');
- Route::get('form/{id}', 'Analisis_laporan@form')->name('analisis_laporan.form');
- Route::get('dialog_kuisioner/{id}/{aksi?}', 'Analisis_laporan@dialog_kuisioner')->name('analisis_laporan.dialog_kuisioner');
- Route::post('daftar/{id}/{aksi?}', 'Analisis_laporan@daftar')->name('analisis_laporan.daftar');
- Route::get('dialog/{aksi?}', 'Analisis_laporan@dialog')->name('analisis_laporan.dialog');
- Route::post('cetak/{aksi?}', 'Analisis_laporan@cetak')->name('analisis_laporan.cetak');
- Route::get('multi_jawab', 'Analisis_laporan@multi_jawab')->name('analisis_laporan.multi_jawab');
- Route::post('multi_exec', 'Analisis_laporan@multi_exec')->name('analisis_laporan.multi_exec');
- Route::get('ajax_multi_jawab', 'Analisis_laporan@ajax_multi_jawab')->name('analisis_laporan.ajax_multi_jawab');
- Route::post('multi_jawab_proses', 'Analisis_laporan@multi_jawab_proses')->name('analisis_laporan.multi_jawab_proses');
-});
-
-Route::group('analisis_statistik_jawaban/{master}', ['namespace' => 'Analisis'], static function (): void {
- Route::get('', 'Analisis_statistik_jawaban@index');
- Route::get('datatables', 'Analisis_statistik_jawaban@datatables')->name('analisis_statistik_jawaban.datatables');
- Route::get('grafik_parameter/{id?}', 'Analisis_statistik_jawaban@grafik_parameter')->name('analisis_statistik_jawaban.grafik_parameter');
- Route::get('subjek_parameter/{id}/{par}', 'Analisis_statistik_jawaban@subjek_parameter')->name('analisis_statistik_jawaban.subjek_parameter');
- Route::post('cetak', 'Analisis_statistik_jawaban@cetak')->name('analisis_statistik_jawaban.cetak');
- Route::get('cetak_subjek/{id}/{par}/{tipe?}', 'Analisis_statistik_jawaban@cetak_subjek')->name('analisis_statistik_jawaban.cetak_subjek');
-});
+