Commit 9ae973ce authored by syaifurplus's avatar syaifurplus

Update ImportDapodikController.php

parent 2789c35f
......@@ -106,7 +106,16 @@ class ImportDapodikController extends Controller
{
$dataPesertaDidik = DapodikSiswaModel::select([
'nama', 'nisn', 'tempat_lahir', 'tanggal_lahir', 'agama', 'alamat', 'rt', 'rw', 'dusun', 'kelurahan', 'kecamatan', 'kode_pos', 'jenis_tinggal', 'telepon', 'hp', 'email', 'nama_ayah', 'pekerjaan_ayah', 'rombel_saat_ini'
])->get();
])
->get();
// Tambahkan pengecekan apakah data ada
if ($dataPesertaDidik->isEmpty()) {
return response()->json([
'status' => 'error',
'message' => 'Tidak ada data yang diambil dari DapodikSiswaModel'
]);
}
$importResults = [
'import_tingkat' => ['berhasil' => 0, 'gagal' => 0],
......@@ -117,11 +126,8 @@ class ImportDapodikController extends Controller
'import_siswa_ortu' => ['berhasil' => 0, 'gagal' => 0],
];
$sekolah = DB::table('perpus_sekolah')->where('id', 1)->first(); // dummy
$dataPesertaDidik->map(function($peserta) use (&$importResults, $sekolah) {
$dataPesertaDidik->map(function($peserta) use (&$importResults) {
try {
// Pastikan kolom rombel_saat_ini valid
if (!$peserta->rombel_saat_ini) {
throw new \Exception("Rombel tidak ditemukan");
......@@ -129,8 +135,6 @@ class ImportDapodikController extends Controller
list($kelas, $jurusan, $kodeKelas) = explode('-', $peserta->rombel_saat_ini);
// Pengecekan jurusan
try {
$jurusanId = DB::table('dummy_perpus_jurusan')->where('nama', $jurusan)->value('id');
if (!$jurusanId) {
$jurusanId = DB::table('dummy_perpus_jurusan')->insertGetId([
......@@ -139,13 +143,7 @@ class ImportDapodikController extends Controller
]);
$importResults['import_jurusan']['berhasil']++;
}
} catch (\Exception $e) {
echo json_encode($e); die;
$importResults['import_jurusan']['gagal']++;
}
// Pengecekan tingkat/kelas
try {
$kelasId = DB::table('dummy_perpus_kelas')->where('nama', $kelas)->value('id');
if (!$kelasId) {
$kelasId = DB::table('dummy_perpus_kelas')->insertGetId([
......@@ -155,13 +153,7 @@ class ImportDapodikController extends Controller
]);
$importResults['import_tingkat']['berhasil']++;
}
} catch (\Exception $e) {
echo json_encode($e); die;
$importResults['import_tingkat']['gagal']++;
}
// Pengecekan kode kelas
try {
$kelasKodeId = DB::table('dummy_perpus_kelasKode')->where([
['nama', '=', $kodeKelas],
['idPSekolah', '=', 1], // dummy
......@@ -177,10 +169,6 @@ class ImportDapodikController extends Controller
]);
$importResults['import_index']['berhasil']++;
}
} catch (\Exception $e) {
echo json_encode($e); die;
$importResults['import_index']['gagal']++;
}
// Cek apakah siswa sudah ada
try {
......@@ -196,7 +184,7 @@ class ImportDapodikController extends Controller
'idPSekolah' => 1, // dummy
'idPKKode' => $kelasKodeId,
'idMAgama' => $idMAgama,
'idPPeriode' => $sekolah->idPPeriode,
'idPPeriode' => 1, // Dummy period
'idMStatus' => 1,
'nisn' => $peserta->nisn ?? '-',
'nama' => $peserta->nama,
......@@ -215,7 +203,7 @@ class ImportDapodikController extends Controller
DB::table('dummy_siswa_mutasi')->insert([
'idSiswa' => $siswaId,
'idPKKode' => $kelasKodeId,
'idPPeriode' => $sekolah->idPPeriode,
'idPPeriode' => 1, // Dummy period
'idMStatus' => 1,
]);
$importResults['import_siswa_mutasi']['berhasil']++;
......@@ -236,16 +224,13 @@ class ImportDapodikController extends Controller
$importResults['import_siswa_mutasi']['gagal']++;
$importResults['import_siswa_ortu']['gagal']++;
}
} catch (\Exception $e) {
// Log error umum untuk satu peserta didik
error_log($e->getMessage());
}
});
return response()->json($importResults);
}
private function getTempatId($jenisTinggal)
{
$tempatMapping = [
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment