Пример #1
0
 public function upload_save(Request $request)
 {
     $this->validate($request, ['excel' => 'required']);
     $inputFileName = $request->excel;
     try {
         $inputFileType = PHPExcel_IOFactory::identify($inputFileName);
         $objReader = PHPExcel_IOFactory::createReader($inputFileType);
         $objPHPExcel = $objReader->load($inputFileName);
     } catch (Exception $e) {
         die('Error loading file "' . pathinfo($inputFileName, PATHINFO_BASENAME) . '": ' . $e->getMessage());
     }
     $sheet = $objPHPExcel->getSheet(0);
     $highestRow = $sheet->getHighestRow();
     $highestColumn = $sheet->getHighestColumn();
     $start = false;
     $data_count = 0;
     $errors = 0;
     $semester = Semester::get_active_semester()->id;
     $id_siswa = null;
     for ($row = 1; $row <= $highestRow; $row++) {
         $rowData = $sheet->rangeToArray('A' . $row . ':' . $highestColumn . $row, NULL, TRUE, FALSE);
         if (!$start) {
             if ($rowData[0][0] == "1" || $rowData[0][0] == "1.") {
                 $start = true;
             }
         }
         if ($start) {
             if (empty($rowData[0][3]) || empty($rowData[0][4])) {
                 continue;
             }
             $data_count++;
             $new = new Pkl();
             if (!empty($rowData[0][1])) {
                 $siswa = Siswa::where('nis', $rowData[0][1])->first();
                 if (!$siswa) {
                     $errors++;
                     $id_siswa = null;
                     continue;
                 }
                 $id_siswa = $siswa->id;
             } else {
                 if ($id_siswa == null) {
                     continue;
                 }
             }
             $created = null;
             $check = Pkl::where('mitra', $rowData[0][3])->where('lokasi', $rowData[0][4])->where('id_siswa', $id_siswa)->where('id_semester', $semester);
             $old = $check->first();
             if ($old) {
                 $created = $old->created_at;
                 $check->delete();
             }
             $new = new Pkl();
             $new->mitra = $rowData[0][3];
             $new->lokasi = $rowData[0][4];
             $new->lama = $rowData[0][5];
             $new->keterangan = $rowData[0][6];
             $new->id_siswa = $id_siswa;
             $new->id_semester = $semester;
             if ($created) {
                 $new->created_at = $created;
             }
             try {
                 $new->save();
             } catch (\Illuminate\Database\QueryException $e) {
                 $errors++;
             }
         }
     }
     if (!$start) {
         $message = "Tidak ada data ditemukan. Pastikan kolom nomor ada pada kolom A dan dimulai dengan angka 1.";
     } else {
         $message = "Upload file selesai. Terbaca ada {$data_count} data. ";
         $message .= $errors > 0 ? "Ada masalah dengan {$errors} data, dan tidak dapat dimasukkan ke dalam database." : "Semua data berhasil ditambahkan.";
     }
     return redirect()->route('nilai.pkl')->with('message', $message);
 }
Пример #2
0
 public function pkl_datalist(Request $request)
 {
     $this->validate($request, ['id_siswa' => 'required|exists:siswa,id', 'id_semester' => 'required|exists:semester,id']);
     $data = Pkl::get_all_catatan($request->input('id_siswa'), $request->input('id_semester'));
     $siswa = Siswa::find($request->input('id_siswa'));
     $tbody = '';
     if (count($data) < 1) {
         $tbody = "<tr><td colspan='99'><center>Tidak ada catatan PKL.</center></td></tr>";
     } else {
         foreach ($data as $i) {
             $tbody .= '<tr><td>' . $i->mitra . '</td>' . '<td>' . $i->lokasi . '</td>' . '<td>' . $i->lama . '</td>' . '<td>' . $i->keterangan . '</td>' . "<td><span class='nobr'>[ <a href=\"javascript:lihat('" . $request->input('id_siswa') . "','" . htmlspecialchars($i->mitra) . "','" . htmlspecialchars($i->lokasi) . "','" . htmlspecialchars($request->input('id_semester')) . "')\">Lihat</a> ]</span> " . "</tr>";
         }
     }
     return ['data' => $tbody, 'siswa' => $siswa->nama];
 }
Пример #3
0
 public function make(Request $request)
 {
     $docObj = new PhpWord();
     $schDetails = Pengaturan::get_school_details();
     $printLocDate = $request->input('tempat_tanggal');
     $headmaster = Pengaturan::get_headmaster();
     $semester = Semester::get_active_semester();
     $siswa_to_print = [];
     $nis_array = [];
     if ($request->input('siswa') == 'kelas') {
         $siswa_to_print = Siswa::where('id_kelas', $request->input('kelas'))->get();
     } elseif ($request->input('siswa') == 'nis') {
         $nis_array = explode(' ', $request->input('nis'));
         foreach ($nis_array as $nis) {
             if (count($range = explode('-', $nis)) == 2) {
                 $range = Siswa::whereBetween('nis', $range)->get();
                 foreach ($range as $get) {
                     $siswa_to_print[] = $get;
                 }
             } elseif ($get = Siswa::where('nis', $nis)->first()) {
                 $siswa_to_print[] = $get;
             } else {
                 return back()->with('message', "NIS {$nis} tidak ditemukan.");
             }
         }
     } else {
         return back();
     }
     if (count($siswa_to_print) < 1) {
         return back()->with('message', "Tidak ada data untuk dicetak.");
     }
     $id_kelas = 0;
     $mapel_list = null;
     foreach ($siswa_to_print as $siswa) {
         if ($siswa->id_kelas == null) {
             continue;
         }
         if (!Semester::is_active_latest()) {
             $siswa->kelas_link->tingkat -= Semester::get_year_difference();
         }
         if ($request->input('cover')) {
             $docObj = $this->wordHalamanCover($docObj, $siswa);
             $docObj = $this->wordHalamanDataSekolah($docObj, $schDetails);
         }
         if ($request->input('bio')) {
             $docObj = $this->wordHalamanBiodata($docObj, $siswa, $printLocDate, $headmaster);
         }
         if ($request->input('nilai')) {
             if ($id_kelas != $siswa->id_kelas) {
                 $id_kelas = $siswa->id_kelas;
                 $mapel_list = NilaiAkhir::get_mapel_list($id_kelas);
             }
             $sikap = NilaiSikap::get_nilai($siswa->id);
             $nilai['sikap'] = $sikap ? $sikap->sikap : "";
             $nilai['mapel'] = NilaiAkhir::get_all_nilai($siswa, $mapel_list);
             $absensi = Absensi::get_absensi($siswa->id);
             $nilai['absensi'] = ['sakit' => $absensi ? $absensi->sakit : null, 'izin' => $absensi ? $absensi->izin : null, 'alpa' => $absensi ? $absensi->alpa : null];
             $nilai['prestasi'] = Prestasi::get_for_print($siswa->id, $semester->id);
             $nilai['ekskul'] = Ekskul::get_for_print($siswa->id, $semester->id);
             $nilai['pkl'] = Pkl::get_for_print($siswa->id, $semester->id);
             $docObj = $this->wordHalamanNilai($docObj, $schDetails, $siswa, $nilai, $headmaster, $printLocDate, $semester);
         }
     }
     $objWriter = IOFactory::createWriter($docObj, 'Word2007');
     $fn = date('Y-n-j_His');
     if ($request->input('siswa') == 'kelas') {
         $kelas = Kelas::find($request->input('kelas'));
         if (!Semester::is_active_latest()) {
             $kelas->tingkat -= Semester::get_year_difference();
         }
         $fn .= "_" . $kelas->name(false);
     }
     if ($request->input('siswa') == 'nis') {
         $fn .= "_" . $nis_array[0] . '-' . $nis_array[count($nis_array) - 1];
     }
     $objWriter->save("print/{$fn}.docx");
     return Response::download("print/{$fn}.docx", "{$fn}.docx", ['Content-Type: application/vnd.openxmlformats-officedocument.wordprocessingml.document']);
 }