2024-03-10 09:07:03 +07:00
< ? php
namespace App\Http\Controllers ;
2024-03-15 18:36:20 +07:00
use App\Jobs\kirimNotifikasiErrorJob ;
use App\Jobs\layananSeminarProposalJob ;
use App\Models\Bagian ;
use App\Models\Mahasiswa ;
2024-03-10 09:07:03 +07:00
use App\Models\PengajuanSempro ;
2024-03-15 18:36:20 +07:00
use App\Models\User ;
use Barryvdh\DomPDF\Facade\Pdf ;
use Carbon\Carbon ;
use Exception ;
2024-03-10 09:07:03 +07:00
use Illuminate\Http\Request ;
2024-03-15 18:36:20 +07:00
use Illuminate\Support\Facades\Storage ;
use SimpleSoftwareIO\QrCode\Facades\QrCode ;
2024-03-10 09:07:03 +07:00
class LayananSeminarProposal extends Controller
{
public function index (){
$data = PengajuanSempro ::
select ( 'pengajuan_sempros.*' ,
'mahasiswas.nim as nim' ,
'mahasiswas.nama as nama' ,
'dosen_dpu.nama_gelar as dpu_nama_gelar' ,
)
-> join ( 'mahasiswas' , 'mahasiswas_id' , '=' , 'mahasiswas.id' )
-> join ( 'users as dosen_dpu' , 'mahasiswas.dosen_dpu_id' , '=' , 'dosen_dpu.id' )
-> get ();
return view ( 'layanan-sempro.index' ,[ 'title' => 'Pengajuan Seminar Proposal | Admin Dashboard' , 'data' => $data ]);
}
2024-03-15 18:36:20 +07:00
//done
public function tambah (){
//ambil data dosen, dan laboratorium
$dosen = User :: role ( 'Dosen' ) -> get ();
$bagian = Bagian :: select ( 'id' , 'nama_bagian' ) -> get ();
//cek apakah ada data mahasiswa dari hasil cari
$nim = session ( 'mahasiswas_id' );
if ( $nim != null ){
$data_mahasiswa = Mahasiswa :: find ( $nim );
return view ( 'layanan-sempro.tambah' ,[ 'dosen' => $dosen , 'bagian' => $bagian , 'data_mahasiswa' => $data_mahasiswa ]);
}
return view ( 'layanan-sempro.tambah' ,[ 'dosen' => $dosen , 'bagian' => $bagian ]);
}
//done
public function cari (){
return view ( 'layanan-sempro.cari' ,[ 'title' => 'Cari Data Mahasiswa Untuk Keperluan Pengajuan Seminar Proposal' ]);
}
//done
public function search ( Request $request ){
$data = Mahasiswa :: where ( 'nim' , $request -> nim ) -> first ();
if ( $data == null ){
return redirect () -> route ( 'layanan-sempro.tambah' ) -> with ( 'error' , 'NIM Tidak Ditemukan, Gunakan Fitur Tambah' );
}
return redirect () -> route ( 'layanan-sempro.tambah' ) -> with ( 'mahasiswas_id' , $data -> id );
}
//done
public function store ( Request $request ){
$request -> validate ([
'nim' => 'required|numeric' ,
'nama' => 'required' ,
'nomor_hp' => 'required|numeric' ,
'email' => 'required|email' ,
'judul_seminar_proposal' => 'required' ,
'bagian' => 'required|numeric' ,
'dosen_dpu' => 'required|numeric' ,
'dosen_dpa' => 'required|numeric' ,
'dosen_penguji1' => 'required|numeric' ,
'dosen_penguji2' => 'required|numeric' ,
'nilai_plagiasi' => 'required|numeric' ,
'bukti_hadir_sempro' => 'required|mimes:pdf|max:4096' ,
'bukti_turnitin' => 'required|mimes:pdf|max:4096' ,
'bukti_sister' => 'required|mimes:pdf|max:4096' ,
'bukti_lembar_monitoring' => 'required|mimes:pdf|max:4096' ,
'bukti_naskah_dosen_pembimbing' => 'required|mimes:pdf|max:4096' ,
'bukti_naskah_dosen_penguji' => 'required|mimes:pdf|max:4096' ,
],[
'nim.required' => 'NIP Wajib Diisi' ,
'nim.numeric' => 'NIM Wajib Berisi Angka saja' ,
'nomor_hp.numeric' => 'Nomor HP Wajib Menggunakan Angka, Contoh 089xxxxx' ,
'email.email' => 'Format email tidak sesuai, cek lagi email anda, Contoh mahasiswa@gmail.com/ mahasiswa@mail.unej.ac.id' ,
'bagian.numeric' => 'Bagian tidak valid, cek kembali Bagian yang dipilih' ,
'dosen_dpu.numeric' => 'Dosen Pembimbing tidak valid, cek kembali Dosen Pembimbing Utama yang dipilih' ,
'dosen_dpa.numeric' => 'Dosen Pembimbing tidak valid, cek kembali Dosen Pembimbing Anggota yang dipilih' ,
'dosen_penguji1.numeric' => 'Dosen Penguji tidak valid, cek kembali Dosen Penguji Utama yang dipilih' ,
'dosen_penguji2.numeric' => 'Dosen Penguji tidak valid, cek kembali Dosen Penguji Anggota yang dipilih' ,
'nilai_plagiasi.numeric' => 'Masukkan Nilai Plagiasi Berupa Angka saja' ,
]);
//olah file
$bukti_hadir_sempro = $request -> file ( 'bukti_hadir_sempro' );
$bukti_turnitin = $request -> file ( 'bukti_turnitin' );
$bukti_sister = $request -> file ( 'bukti_sister' );
$bukti_lembar_monitoring = $request -> file ( 'bukti_lembar_monitoring' );
$bukti_naskah_dosen_pembimbing = $request -> file ( 'bukti_naskah_dosen_pembimbing' );
$bukti_naskah_dosen_penguji = $request -> file ( 'bukti_naskah_dosen_penguji' );
//beri nama tiap file
$bukti_hadir_sempro_name = 'LP_1' . str_replace ( ' ' , '_' , $bukti_hadir_sempro -> getClientOriginalName ());
$bukti_turnitin_name = 'LP_2' . str_replace ( ' ' , '_' , $bukti_turnitin -> getClientOriginalName ());
$bukti_sister_name = 'LP_3' . str_replace ( ' ' , '_' , $bukti_sister -> getClientOriginalName ());
$bukti_lembar_monitoring_name = 'LP_4' . str_replace ( ' ' , '_' , $bukti_lembar_monitoring -> getClientOriginalName ());
$bukti_naskah_dosen_pembimbing_name = 'LP_5' . str_replace ( ' ' , '_' , $bukti_naskah_dosen_pembimbing -> getClientOriginalName ());
$bukti_naskah_dosen_penguji_name = 'LP_6' . str_replace ( ' ' , '_' , $bukti_naskah_dosen_penguji -> getClientOriginalName ());
//cek apakah data mahasiswa ada, jika ada maka dikembalikan dan dianjurkan menggunakan fitur cari
$mahasiswa = Mahasiswa :: where ( 'nim' , $request -> nim ) -> first ();
if ( ! is_null ( $mahasiswa ) && $request -> status != " ada " ){
return redirect () -> route ( 'layanan-sempro.tambah' ) -> with ( 'error' , 'Data Anda Sudah Ada, Gunakan Fitur Cari Menggunakan NIM :' . $request -> nim );
}
//kalo menggunakan fitur cari, akan menggunakan fungsi ini
elseif ( ! is_null ( $mahasiswa ) && $request -> status == " ada " ){
$mahasiswas_id = $mahasiswa -> id ;
$data_sempro [ 'mahasiswas_id' ] = $mahasiswas_id ;
$data_sempro [ 'nilai_plagiasi' ] = $request -> nilai_plagiasi ;
$data_sempro [ 'bukti_hadir_sempro' ] = $bukti_hadir_sempro_name ;
$data_sempro [ 'bukti_turnitin' ] = $bukti_turnitin_name ;
$data_sempro [ 'bukti_sister' ] = $bukti_sister_name ;
$data_sempro [ 'bukti_lembar_monitoring' ] = $bukti_lembar_monitoring_name ;
$data_sempro [ 'bukti_naskah_dosen_pembimbing' ] = $bukti_naskah_dosen_pembimbing_name ;
$data_sempro [ 'bukti_naskah_dosen_penguji' ] = $bukti_naskah_dosen_penguji_name ;
PengajuanSempro :: create ( $data_sempro );
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_hadir_sempro_name , file_get_contents ( $bukti_hadir_sempro ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_turnitin_name , file_get_contents ( $bukti_turnitin ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_sister_name , file_get_contents ( $bukti_sister ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_lembar_monitoring_name , file_get_contents ( $bukti_lembar_monitoring ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_naskah_dosen_pembimbing_name , file_get_contents ( $bukti_naskah_dosen_pembimbing ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_naskah_dosen_penguji_name , file_get_contents ( $bukti_naskah_dosen_penguji ));
return redirect () -> route ( 'layanan-sempro.tambah' ) -> with ( 'success' , 'Sukses Tambah Data, Silahkan Menunggu Email Konfirmasi setelah disetujui Oleh Operator' );
}
$data_mhs [ 'nim' ] = $request -> nim ;
$data_mhs [ 'nama' ] = $request -> nama ;
$data_mhs [ 'nomor_hp' ] = $request -> nomor_hp ;
$data_mhs [ 'email' ] = $request -> email ;
$data_mhs [ 'judul_seminar_proposal' ] = $request -> judul_seminar_proposal ;
$data_mhs [ 'bagian' ] = $request -> bagian ;
$data_mhs [ 'dosen_dpu_id' ] = $request -> dosen_dpu ;
$data_mhs [ 'dosen_dpa_id' ] = $request -> dosen_dpa ;
$data_mhs [ 'dosen_penguji1_id' ] = $request -> dosen_penguji1 ;
$data_mhs [ 'dosen_penguji2_id' ] = $request -> dosen_penguji2 ;
//set default values to -
$data_mhs [ 'judul_skripsi_id' ] = '-' ;
$data_mhs [ 'judul_skripsi_en' ] = '-' ;
$data_mhs [ 'judul_jurnal' ] = '-' ;
$data_mhs [ 'judul_artikel' ] = '-' ;
//save data mahasiswa dan pengajuan
if ( Mahasiswa :: create ( $data_mhs )){
$mahasiswas_id = Mahasiswa :: where ( 'nim' , $request -> nim ) -> first ();
$data_sempro [ 'mahasiswas_id' ] = $mahasiswas_id -> id ;
$data_sempro [ 'nilai_plagiasi' ] = $request -> nilai_plagiasi ;
$data_sempro [ 'bukti_hadir_sempro' ] = $bukti_hadir_sempro_name ;
$data_sempro [ 'bukti_turnitin' ] = $bukti_turnitin_name ;
$data_sempro [ 'bukti_sister' ] = $bukti_sister_name ;
$data_sempro [ 'bukti_lembar_monitoring' ] = $bukti_lembar_monitoring_name ;
$data_sempro [ 'bukti_naskah_dosen_pembimbing' ] = $bukti_naskah_dosen_pembimbing_name ;
$data_sempro [ 'bukti_naskah_dosen_penguji' ] = $bukti_naskah_dosen_penguji_name ;
PengajuanSempro :: create ( $data_sempro );
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_hadir_sempro_name , file_get_contents ( $bukti_hadir_sempro ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_turnitin_name , file_get_contents ( $bukti_turnitin ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_sister_name , file_get_contents ( $bukti_sister ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_lembar_monitoring_name , file_get_contents ( $bukti_lembar_monitoring ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_naskah_dosen_pembimbing_name , file_get_contents ( $bukti_naskah_dosen_pembimbing ));
Storage :: disk ( 'public' ) -> put ( $request -> nim . '/' . $bukti_naskah_dosen_penguji_name , file_get_contents ( $bukti_naskah_dosen_penguji ));
return redirect () -> route ( 'layanan-sempro.tambah' ) -> with ( 'success' , 'Sukses Tambah Data, Silahkan Menunggu Email Konfirmasi setelah disetujui Oleh Operator' );
}
return redirect () -> route ( 'layanan-sempro.tambah' ) -> with ( 'error' , 'Gagal Tambah data, Cek kembali data yang anda masukkan' );
}
//done
2024-03-10 09:07:03 +07:00
public function destroy ( Request $request ){
2024-03-15 18:36:20 +07:00
$id = $request -> id ;
//cari data dan kirim notif sebelum dihapus
$data = PengajuanSempro :: where ( 'pengajuan_sempros.id' , $id )
-> join ( 'mahasiswas' , 'mahasiswas_id' , '=' , 'mahasiswas.id' )
-> first ();
//data yang akan dikirim untuk dihapus
$data_job = [
'jenis' => 'penolakan' ,
'nama' => $data -> nama ,
'email' => $data -> email ,
'created_at' => $data -> created_at ,
'alasan' => $request -> alasan ,
];
//lokasi file
$path = [
'bukti_hadir_sempro' => $data -> nim . " / " . $data -> bukti_hadir_sempro ,
'bukti_turnitin' => $data -> nim . " / " . $data -> bukti_turnitin ,
'bukti_sister' => $data -> nim . " / " . $data -> bukti_sister ,
'bukti_lembar_monitoring' => $data -> nim . " / " . $data -> bukti_lembar_monitoring ,
'bukti_naskah_dosen_pembimbing' => $data -> nim . " / " . $data -> bukti_naskah_dosen_pembimbing ,
'bukti_naskah_dosen_penguji' => $data -> nim . " / " . $data -> bukti_naskah_dosen_penguji ,
];
//delete file
foreach ( $path as $item ){
try {
Storage :: disk ( 'public' ) -> delete ( $item );
}
catch ( Exception $e ){
$text [ 'error' ] = $e -> getMessage ();
dispatch ( new kirimNotifikasiErrorJob ( $text ));
2024-03-20 17:08:09 +07:00
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'error' , 'Error : ' . $text [ 'error' ]);
2024-03-15 18:36:20 +07:00
}
}
//delete data mahasiswa
try {
$dataDelete = PengajuanSempro :: findOrFail ( $id );
$dataDelete -> delete ();
//kirim notif ke mahasiswa bahwa ditolak
dispatch ( new layananSeminarProposalJob ( $data_job ));
} catch ( Exception $e ){
//kirim notif error jika terjadi error
$text [ 'error' ] = $e -> getMessage ();
dispatch ( new kirimNotifikasiErrorJob ( $text ));
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'error' , 'Error : ' . $text [ 'error' ]);
}
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'success' , 'Permintaan Sudah Diproses, Email akan segera dikirim ke penerima' );
2024-03-10 09:07:03 +07:00
}
2024-03-15 18:36:20 +07:00
//done
2024-03-10 09:07:03 +07:00
public function terima ( Request $request ){
2024-03-15 18:36:20 +07:00
$id = $request -> id ;
$countcaseid = PengajuanSempro :: where ( 'ttd_operator' , '!=' , '-' ) -> count ();
$caseid = " LP " . date_format ( date_create (), " ym " ) . $countcaseid + 1 ;
$cekData = PengajuanSempro :: where ( 'caseid' , $caseid ) -> first ();
$data = PengajuanSempro :: where ( 'id' , $id ) -> first ();
//cek apakah ada caseid yang sama sebelum disave
if ( ! is_null ( $cekData )){
$data -> updated_at = Carbon :: now ();
$data -> save ();
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'error' , 'Gagal simpan Data, Cek kembali Detail Data yang akan diterima' );
}
$data -> caseid = $caseid ;
$data -> ttd_operator = Carbon :: now ();
if ( $data -> save ()){
$data_job = [
[
'jenis' => 'mahasiswa' ,
'id' => $id ,
],
[
'jenis' => 'dpu' ,
'id' => $id ,
],
];
foreach ( $data_job as $item ){
dispatch ( new layananSeminarProposalJob ( $item ));
}
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'success' , 'Data Berhasil Disimpan, Email Akan Dikirimkan ke Mahasiswa, DPU dan DPA' );
}
}
//done
public function ettd ( $caseid ){
$data = PengajuanSempro :: where ( 'caseid' , $caseid )
-> select (
'pengajuan_sempros.*' ,
'mahasiswas.nama' ,
'mahasiswas.nim' ,
'mahasiswas.judul_seminar_proposal' ,
'dosen_dpu.nama_gelar as dosen_dpu_nama_gelar' ,
)
-> join ( 'mahasiswas' , 'pengajuan_sempros.mahasiswas_id' , '=' , 'mahasiswas.id' )
-> join ( 'users as dosen_dpu' , 'mahasiswas.dosen_dpu_id' , '=' , 'dosen_dpu.id' )
-> first ();
//jika data tidak null, maka render ini
if ( ! is_null ( $data )){
$jenis = 'Dosen Pembimbing Utama' ;
return view ( 'layanan-sempro.ettd' ,[ 'title' => 'INPUT E-Signature' , 'jenis' => $jenis , 'data' => $data ]);
}
//jika URL tidak diantara ketika itu maka render ini
return redirect () -> route ( 'laman-awal' ) -> with ([ 'error' => 'Invalid CASEID, Atau CaseID Tidak Ditemukan' ]);
}
2024-03-10 09:07:03 +07:00
2024-03-15 18:36:20 +07:00
//done
public function submitettd ( $caseid , Request $request ){
$data = PengajuanSempro :: where ( 'caseid' , '=' , $caseid ) -> first ();
//jika data ada, maka diproses
if ( ! is_null ( $data )){
//cek ttd jika ttd sudah pernah diisi maka dikembalikan error
if ( $data -> ttd_dpu != '-' ){
return redirect () -> route ( 'layanan-sempro.ettd' ,[ 'caseid' => $caseid ]) -> with ([ 'error' => 'CaseID Ini Sudah Pernah Anda Tandatangani Pada ' . $data -> ttd_dpu ]);
}
$ttd = Mahasiswa :: where ( 'nim' , $request -> nim ) -> join ( 'users as dosen_dpu' , 'mahasiswas.dosen_dpu_id' , '=' , 'dosen_dpu.id' ) -> first ();
//jika Belum Pernah maka TTD akan diproses
if ( $ttd -> ettd == $request -> ettd ){
$data -> ttd_dpu = Carbon :: now ();
$data -> save ();
$data_job = [
'jenis' => 'mahasiswa selesai' ,
'id' => $data -> id ,
];
dispatch ( new layananSeminarProposalJob ( $data_job ));
return redirect () -> route ( 'monitoring.caseid' ,[ 'caseid' => $caseid ]) -> with ([ 'success' => 'Terimakasih Telah Melakukan Tanda Tangan Pada CaseID ' . $caseid ]);
}
//jika ETTD Tidak sesuai Akan Dikembalikan Ke laman TTD Dengan error
else {
return redirect () -> route ( 'layanan-sempro.ettd' ,[ 'caseid' => $caseid ]) -> with ([ 'error' => 'E-TTD Tidak Sesuai, Cek Kembali ETTD Anda' ]);
}
}
2024-03-10 09:07:03 +07:00
}
2024-03-15 18:36:20 +07:00
//done
public function cetak ( $caseid ){
$data = PengajuanSempro :: where ( 'caseid' , $caseid )
-> select (
'pengajuan_sempros.*' ,
'mahasiswas.nama' ,
'bagians.nama_bagian' ,
'mahasiswas.nim' ,
'mahasiswas.judul_seminar_proposal' ,
'dosen_dpu.nama_gelar as dosen_dpu_nama_gelar' ,
'dosen_dpu.nip as dosen_dpu_nip' ,
)
-> join ( 'mahasiswas' , 'pengajuan_sempros.mahasiswas_id' , '=' , 'mahasiswas.id' )
-> join ( 'bagians' , 'mahasiswas.bagian' , '=' , 'bagians.id' )
-> join ( 'users as dosen_dpu' , 'mahasiswas.dosen_dpu_id' , '=' , 'dosen_dpu.id' )
-> first ();
//jika data tidak null, maka render ini
if ( $data -> ttd_dpu == '-' ){
return redirect () -> route ( 'monitoring.caseid' ,[ 'caseid' => $caseid ]) -> with ( 'error' , 'Data Belum Di TandaTangani Oleh Dosen Pembimbing Utama, File Bisa didownload ketika DPU sudah tanda tangan!' );
}
if ( is_null ( $data )){
return redirect () -> route ( 'monitoring.caseid' ,[ 'caseid' => $caseid ]) -> with ( 'error' , 'Data Dengan CASEID Tersebut Tidak ada' );
}
$data = [
'title' => 'Cetak Kesediaan' ,
// 'date' => Carbon::now()->format('d-m-Y'),
'date' => $data -> created_at -> format ( 'd-m-Y' ),
'nama_mahasiswa' => $data -> nama ,
'nim' => $data -> nim ,
'bagian' => $data -> nama_bagian ,
'judul_seminar_proposal' => $data -> judul_seminar_proposal ,
'nilai_plagiasi' => $data -> nilai_plagiasi ,
'dosen_dpu_nama_gelar' => $data -> dosen_dpu_nama_gelar ,
'dosen_dpu_nip' => $data -> dosen_dpu_nip ,
'dosen_dpu_qrcode' => base64_encode ( QrCode :: size ( 100 ) -> generate ( $data -> dosen_dpu_nama_gelar . '_TTD_' . $data -> ttd_dpu )),
];
$pdf = Pdf :: loadView ( 'layanan-sempro.cetak' , $data );
return $pdf -> setPaper ( 'a4' , 'potrait' ) -> stream ( $caseid . '-Kesediaan Menjadi Dosen Pembimbing Tugas Akhir' );
//jika URL tidak diantara ketika itu maka render ini
}
2024-03-20 17:08:09 +07:00
public function resend ( $caseid , Request $request ){
try {
$data = PengajuanSempro :: where ( 'caseid' , $caseid ) -> first ();
$data_job = [
'id' => $data -> id ,
'jenis' => $request -> jenis ,
];
dispatch ( new layananSeminarProposalJob ( $data_job ));
} catch ( Exception $e ){
$text [ 'error' ] = $e -> getMessage ();
dispatch ( new kirimNotifikasiErrorJob ( $text ));
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'error' , 'Error : ' . $text [ 'error' ]);
}
return redirect () -> route ( 'layanan-sempro.index' ) -> with ( 'success' , 'Berhasil Kirim Ulang Email Kepada ' . $request -> jenis . ' Dengan CaseID : ' . $caseid );
}
2024-03-10 09:07:03 +07:00
}