Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sibiling
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
1
Issues
1
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Syaifur
sibiling
Commits
9ae973ce
Commit
9ae973ce
authored
Sep 06, 2024
by
syaifurplus
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update ImportDapodikController.php
parent
2789c35f
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
101 additions
and
116 deletions
+101
-116
ImportDapodikController.php
...Http/Controllers/Admin/Import/ImportDapodikController.php
+101
-116
No files found.
app/Http/Controllers/Admin/Import/ImportDapodikController.php
View file @
9ae973ce
...
@@ -106,7 +106,16 @@ class ImportDapodikController extends Controller
...
@@ -106,7 +106,16 @@ class ImportDapodikController extends Controller
{
{
$dataPesertaDidik
=
DapodikSiswaModel
::
select
([
$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'
'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
=
[
$importResults
=
[
'import_tingkat'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_tingkat'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
...
@@ -117,128 +126,103 @@ class ImportDapodikController extends Controller
...
@@ -117,128 +126,103 @@ class ImportDapodikController extends Controller
'import_siswa_ortu'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
'import_siswa_ortu'
=>
[
'berhasil'
=>
0
,
'gagal'
=>
0
],
];
];
$sekolah
=
DB
::
table
(
'perpus_sekolah'
)
->
where
(
'id'
,
1
)
->
first
();
// dummy
$dataPesertaDidik
->
map
(
function
(
$peserta
)
use
(
&
$importResults
)
{
$dataPesertaDidik
->
map
(
function
(
$peserta
)
use
(
&
$importResults
,
$sekolah
)
{
// Pastikan kolom rombel_saat_ini valid
if
(
!
$peserta
->
rombel_saat_ini
)
{
try
{
throw
new
\Exception
(
"Rombel tidak ditemukan"
);
// Pastikan kolom rombel_saat_ini valid
}
if
(
!
$peserta
->
rombel_saat_ini
)
{
throw
new
\Exception
(
"Rombel tidak ditemukan"
);
}
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
([
'idPSekolah'
=>
1
,
// dummy
'nama'
=>
$jurusan
,
]);
$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
([
'idPSekolah'
=>
1
,
// dummy
'idPJurusan'
=>
$jurusanId
,
'nama'
=>
$kelas
,
]);
$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
[
'idPJurusan'
,
'='
,
$jurusanId
],
[
'idPKelas'
,
'='
,
$kelasId
],
])
->
value
(
'id'
);
if
(
!
$kelasKodeId
)
{
$kelasKodeId
=
DB
::
table
(
'dummy_perpus_kelasKode'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idPJurusan'
=>
$jurusanId
,
'idPKelas'
=>
$kelasId
,
'nama'
=>
$kodeKelas
,
]);
$importResults
[
'import_index'
][
'berhasil'
]
++
;
}
}
catch
(
\Exception
$e
)
{
echo
json_encode
(
$e
);
die
;
$importResults
[
'import_index'
][
'gagal'
]
++
;
}
// Cek apakah siswa sudah ada
list
(
$kelas
,
$jurusan
,
$kodeKelas
)
=
explode
(
'-'
,
$peserta
->
rombel_saat_ini
);
try
{
$existingSiswa
=
DB
::
table
(
'dummy_siswa'
)
->
where
(
'nisn'
,
$peserta
->
nisn
)
->
first
();
if
(
!
$existingSiswa
)
{
$jurusanId
=
DB
::
table
(
'dummy_perpus_jurusan'
)
->
where
(
'nama'
,
$jurusan
)
->
value
(
'id'
);
$alamatLengkap
=
$peserta
->
alamat
.
', RT: '
.
(
$peserta
->
rt
??
'-'
)
.
', RW: '
.
(
$peserta
->
rw
??
'-'
)
.
', Dusun: '
.
(
$peserta
->
dusun
??
'-'
)
.
', Kelurahan: '
.
(
$peserta
->
kelurahan
??
'-'
)
.
', Kecamatan: '
.
(
$peserta
->
kecamatan
??
'-'
)
.
', Kode Pos: '
.
(
$peserta
->
kode_pos
??
'-'
);
if
(
!
$jurusanId
)
{
$jurusanId
=
DB
::
table
(
'dummy_perpus_jurusan'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'nama'
=>
$jurusan
,
]);
$importResults
[
'import_jurusan'
][
'berhasil'
]
++
;
}
$idMTempat
=
$this
->
getTempatId
(
$peserta
->
jenis_tinggal
);
$kelasId
=
DB
::
table
(
'dummy_perpus_kelas'
)
->
where
(
'nama'
,
$kelas
)
->
value
(
'id'
);
$idMAgama
=
$this
->
getAgamaId
(
$peserta
->
agama
);
if
(
!
$kelasId
)
{
$kelasId
=
DB
::
table
(
'dummy_perpus_kelas'
)
->
insertGetId
([
'idPSekolah'
=>
1
,
// dummy
'idPJurusan'
=>
$jurusanId
,
'nama'
=>
$kelas
,
]);
$importResults
[
'import_tingkat'
][
'berhasil'
]
++
;
}
$siswaId
=
DB
::
table
(
'dummy_siswa'
)
->
insertGetId
([
$kelasKodeId
=
DB
::
table
(
'dummy_perpus_kelasKode'
)
->
where
([
'idPSekolah'
=>
1
,
// dummy
[
'nama'
,
'='
,
$kodeKelas
],
'idPKKode'
=>
$kelasKodeId
,
[
'idPSekolah'
,
'='
,
1
],
// dummy
'idMAgama'
=>
$idMAgama
,
[
'idPJurusan'
,
'='
,
$jurusanId
],
'idPPeriode'
=>
$sekolah
->
idPPeriode
,
[
'idPKelas'
,
'='
,
$kelasId
],
'idMStatus'
=>
1
,
])
->
value
(
'id'
);
'nisn'
=>
$peserta
->
nisn
??
'-'
,
if
(
!
$kelasKodeId
)
{
'nama'
=>
$peserta
->
nama
,
$kelasKodeId
=
DB
::
table
(
'dummy_perpus_kelasKode'
)
->
insertGetId
([
'lahir_tanggal'
=>
$peserta
->
tanggal_lahir
,
'idPSekolah'
=>
1
,
// dummy
'lahir_tempat'
=>
$peserta
->
tempat_lahir
,
'idPJurusan'
=>
$jurusanId
,
'idPPKelas'
=>
$kelasId
,
'idPKelas'
=>
$kelasId
,
'idPPStatus'
=>
1
,
'nama'
=>
$kodeKelas
,
'idMTempat'
=>
$idMTempat
,
]);
'email'
=>
$peserta
->
email
??
'-'
,
$importResults
[
'import_index'
][
'berhasil'
]
++
;
'telp'
=>
$peserta
->
hp
??
$peserta
->
telepon
??
'-'
,
}
'alamat'
=>
$alamatLengkap
,
]);
$importResults
[
'import_siswa'
][
'berhasil'
]
++
;
// Insert ke siswa_mutasi
// Cek apakah siswa sudah ada
DB
::
table
(
'dummy_siswa_mutasi'
)
->
insert
([
try
{
'idSiswa'
=>
$siswaId
,
$existingSiswa
=
DB
::
table
(
'dummy_siswa'
)
->
where
(
'nisn'
,
$peserta
->
nisn
)
->
first
();
'idPKKode'
=>
$kelasKodeId
,
'idPPeriode'
=>
$sekolah
->
idPPeriode
,
if
(
!
$existingSiswa
)
{
'idMStatus'
=>
1
,
$alamatLengkap
=
$peserta
->
alamat
.
', RT: '
.
(
$peserta
->
rt
??
'-'
)
.
', RW: '
.
(
$peserta
->
rw
??
'-'
)
.
', Dusun: '
.
(
$peserta
->
dusun
??
'-'
)
.
', Kelurahan: '
.
(
$peserta
->
kelurahan
??
'-'
)
.
', Kecamatan: '
.
(
$peserta
->
kecamatan
??
'-'
)
.
', Kode Pos: '
.
(
$peserta
->
kode_pos
??
'-'
);
]);
$importResults
[
'import_siswa_mutasi'
][
'berhasil'
]
++
;
$idMTempat
=
$this
->
getTempatId
(
$peserta
->
jenis_tinggal
);
$idMAgama
=
$this
->
getAgamaId
(
$peserta
->
agama
);
// Insert ke ortu
$idMPekerjaan
=
$this
->
getPekerjaanId
(
$peserta
->
pekerjaan_ayah
);
$siswaId
=
DB
::
table
(
'dummy_siswa'
)
->
insertGetId
([
DB
::
table
(
'dummy_ortu'
)
->
insert
([
'idPSekolah'
=>
1
,
// dummy
'idPSekolah'
=>
1
,
'idPKKode'
=>
$kelasKodeId
,
'idSiswa'
=>
$siswaId
,
'idMAgama'
=>
$idMAgama
,
'idMPekerjaan'
=>
$idMPekerjaan
,
'idPPeriode'
=>
1
,
// Dummy period
'nama'
=>
$peserta
->
nama_ayah
,
'idMStatus'
=>
1
,
'alamat'
=>
$alamatLengkap
,
'nisn'
=>
$peserta
->
nisn
??
'-'
,
]);
'nama'
=>
$peserta
->
nama
,
$importResults
[
'import_siswa_ortu'
][
'berhasil'
]
++
;
'lahir_tanggal'
=>
$peserta
->
tanggal_lahir
,
}
'lahir_tempat'
=>
$peserta
->
tempat_lahir
,
}
catch
(
\Exception
$e
)
{
'idPPKelas'
=>
$kelasId
,
$importResults
[
'import_siswa'
][
'gagal'
]
++
;
'idPPStatus'
=>
1
,
$importResults
[
'import_siswa_mutasi'
][
'gagal'
]
++
;
'idMTempat'
=>
$idMTempat
,
$importResults
[
'import_siswa_ortu'
][
'gagal'
]
++
;
'email'
=>
$peserta
->
email
??
'-'
,
'telp'
=>
$peserta
->
hp
??
$peserta
->
telepon
??
'-'
,
'alamat'
=>
$alamatLengkap
,
]);
$importResults
[
'import_siswa'
][
'berhasil'
]
++
;
// Insert ke siswa_mutasi
DB
::
table
(
'dummy_siswa_mutasi'
)
->
insert
([
'idSiswa'
=>
$siswaId
,
'idPKKode'
=>
$kelasKodeId
,
'idPPeriode'
=>
1
,
// Dummy period
'idMStatus'
=>
1
,
]);
$importResults
[
'import_siswa_mutasi'
][
'berhasil'
]
++
;
// Insert ke ortu
$idMPekerjaan
=
$this
->
getPekerjaanId
(
$peserta
->
pekerjaan_ayah
);
DB
::
table
(
'dummy_ortu'
)
->
insert
([
'idPSekolah'
=>
1
,
'idSiswa'
=>
$siswaId
,
'idMPekerjaan'
=>
$idMPekerjaan
,
'nama'
=>
$peserta
->
nama_ayah
,
'alamat'
=>
$alamatLengkap
,
]);
$importResults
[
'import_siswa_ortu'
][
'berhasil'
]
++
;
}
}
}
catch
(
\Exception
$e
)
{
}
catch
(
\Exception
$e
)
{
// Log error umum untuk satu peserta didik
$importResults
[
'import_siswa'
][
'gagal'
]
++
;
error_log
(
$e
->
getMessage
());
$importResults
[
'import_siswa_mutasi'
][
'gagal'
]
++
;
$importResults
[
'import_siswa_ortu'
][
'gagal'
]
++
;
}
}
});
});
...
@@ -246,6 +230,7 @@ class ImportDapodikController extends Controller
...
@@ -246,6 +230,7 @@ class ImportDapodikController extends Controller
}
}
private
function
getTempatId
(
$jenisTinggal
)
private
function
getTempatId
(
$jenisTinggal
)
{
{
$tempatMapping
=
[
$tempatMapping
=
[
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment