Skip to content

Commit

Permalink
menambahkan fitur kamar, mapel, riwayat yang sudah fix
Browse files Browse the repository at this point in the history
  • Loading branch information
AhmadMuzayyin committed Sep 10, 2023
1 parent aaf3e54 commit ceeed72
Show file tree
Hide file tree
Showing 52 changed files with 1,759 additions and 161 deletions.
36 changes: 21 additions & 15 deletions app/Http/Controllers/Api/synchronizationController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@

namespace App\Http\Controllers\Api;

use Carbon\Carbon;
use App\Models\User;
use App\Http\Controllers\Controller;
use App\Models\Kamar;
use App\Models\Kelas;
use App\Models\Santri;
use App\Models\User;
use App\Models\WaliSantri;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use Carbon\Carbon;
use Helper;
use Illuminate\Http\Request;
use Illuminate\Support\Str;
use Intervention\Image\Facades\Image;

class synchronizationController extends Controller
Expand All @@ -20,12 +20,14 @@ class synchronizationController extends Controller
public function get_kelas()
{
$kelas = Kelas::all();

return response()->json([
'status' => true,
'message' => 'get all data kelas',
'data' => $kelas
'data' => $kelas,
], 200);
}

public function store_kelas(Request $request)
{
$validate = $request->validate([
Expand All @@ -35,10 +37,11 @@ public function store_kelas(Request $request)
]);
try {
$kelas = Kelas::create($validate);

return response()->json([
'status' => true,
'message' => 'successfully created data',
'data' => $kelas
'data' => $kelas,
], 201);
} catch (\Throwable $th) {
return response()->json([
Expand All @@ -52,12 +55,14 @@ public function store_kelas(Request $request)
public function get_santri()
{
$kelas = Kelas::all();

return response()->json([
'status' => true,
'message' => 'get all data kelas',
'data' => $kelas
'data' => $kelas,
], 200);
}

public function store_santri(Request $request)
{
$validate = $request->validate([
Expand Down Expand Up @@ -103,19 +108,19 @@ public function store_santri(Request $request)
$validate['kelas_id'] = $validate['kelas'];
$validate['tahun_masuk_hijriyah'] = str_replace('/', '-', $date->toHijri()->isoFormat('L'));
$validate['status'] = isset($request->tanggal_boyong) == true ? 'Santri Alumni' : 'Santri Aktif';
$validate['whatsapp'] = '62' . $request->whatsapp;
$validate['whatsapp'] = '62'.$request->whatsapp;
$tgl = Carbon::parse($request->tanggal_boyong);
$validate['tanggal_boyong_hijriyah'] = isset($request->tanggal_boyong) ? str_replace('/', '-', $tgl->toHijri()->isoFormat('LL')) : '';
$foto = $request->file('foto');
if (isset($foto) == false) {
$user = User::create([
'name' => $request->nama_lengkap,
'email' => 'santri_' . Str::slug($request->nama_lengkap) . '@digitren.net',
'email' => 'santri_'.Str::slug($request->nama_lengkap).'@digitren.net',
'password' => bcrypt('password'),
]);
$validate['user_id'] = $user->id;
$santri = Santri::create($validate);
if (!$santri) {
if (! $santri) {
$user->delete();
}
// insert wali santri
Expand All @@ -135,19 +140,19 @@ public function store_santri(Request $request)
$path = storage_path('app/public/uploads/santri/');
$filename = $foto->hashName();

if (!file_exists($path)) {
if (! file_exists($path)) {
mkdir($path, 0777, true);
}

Image::make($foto->getRealPath())->resize(400, 400, function ($constraint) {
$constraint->upsize();
$constraint->aspectRatio();
})->save($path . $filename);
})->save($path.$filename);

// insert user login santri
$user = User::create([
'name' => $request->nama_lengkap,
'email' => 'santri_' . Str::slug($request->nama_lengkap) . '@digitren.net',
'email' => 'santri_'.Str::slug($request->nama_lengkap).'@digitren.net',
'password' => bcrypt('password'),
]);

Expand All @@ -174,10 +179,11 @@ public function store_santri(Request $request)
$kamar->update([
'jumlah_santri' => $kamar->jumlah_santri + 1,
]);

return response()->json([
'status' => true,
'message' => 'successfully created data',
'data' => $santri
'data' => $santri,
], 201);
} catch (\Throwable $th) {
return response()->json([
Expand Down
9 changes: 9 additions & 0 deletions app/Http/Controllers/Auth/AuthController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Models\ActivityLog;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

Expand All @@ -20,6 +21,10 @@ public function auth(Request $request)
'password' => 'required|min:8',
]);
if (Auth::attempt($validate)) {
ActivityLog::create([
'user_id' => auth()->user()->id,
'activity' => auth()->user()->name . ' Login pada ' . date('d F Y H:i s')
]);
$request->session()->regenerate();

return redirect()->intended(route('dashboard'));
Expand All @@ -31,6 +36,10 @@ public function auth(Request $request)

public function logout(Request $request)
{
ActivityLog::create([
'user_id' => auth()->user()->id,
'activity' => auth()->user()->name . ' Logout pada ' . date('d F Y H:i s')
]);
Auth::logout();
$request->session()->regenerateToken();

Expand Down
73 changes: 73 additions & 0 deletions app/Http/Controllers/Kamar/KamarController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
<?php

namespace App\Http\Controllers\Kamar;

use App\Http\Controllers\Controller;
use App\Models\Kamar;
use Illuminate\Http\Request;
use Toastr;

class KamarController extends Controller
{
public function index()
{
$kamar = Kamar::all();

return view('pages.kamar.index', compact('kamar'));
}

public function store(Request $request)
{
$validate = $request->validate([
'nama' => 'required|min:3|unique:kamars,nama',
'blok' => 'required|min:1',
'jumlah_santri' => 'required|numeric|min:0',
'maksimal_santri' => 'required|numeric|min:0',
]);

try {
Kamar::create($validate);
Toastr::success('Berhasil menambah data');
return redirect()->back();
} catch (\Throwable $th) {
Toastr::error('Gagal menambah data');
return redirect()->back();
}
}

public function update(Request $request, Kamar $kamar)
{
$validate = $request->validate([
'nama' => "required|min:3|unique:kamars,nama,$kamar->id",
'blok' => 'required|min:1',
'jumlah_santri' => 'required|numeric|min:0',
'maksimal_santri' => 'required|numeric|min:0',
]);
try {
$kamar->update($validate);
Toastr::success('Berhasil merubah data');

return redirect()->back();
} catch (\Throwable $th) {
Toastr::error('Gagal merubah data');

return redirect()->back()->withInput();
}
}

public function destroy(Kamar $kamar)
{
try {
if ($kamar->jumlah_santri == 0) {
$kamar->delete();
Toastr::success('Berhasil menghapus data');
} else {
Toastr::info('Kamar telah diisi, tidak dapat dihapus');
}
return redirect()->back();
} catch (\Throwable $th) {
Toastr::error('Gagal menghapus data');
return redirect()->back();
}
}
}
31 changes: 31 additions & 0 deletions app/Http/Controllers/MapelController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

namespace App\Http\Controllers;

use App\Models\MataPelajaran;
use Illuminate\Http\Request;
use Toastr;

class MapelController extends Controller
{
public function index()
{
$mapel = MataPelajaran::all();
return view('pages.mapel.index', compact('mapel'));
}
public function store(Request $request)
{
$validate = $request->validate([
'kategori' => 'required|in:Fan Pokok, Non Pokok, Tes Kelas Tertentu, Absensi, Kondisi Siswa',
'nama' => 'required|string|min:5'
]);
try {
MataPelajaran::create($validate);
Toastr::success('Berhasil menyimpan data');
return redirect()->back();
} catch (\Throwable $th) {
Toastr::error('Gagal menyimpan data');
return redirect()->back();
}
}
}
40 changes: 40 additions & 0 deletions app/Http/Controllers/Rapor/RaportSantriController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace App\Http\Controllers\Rapor;

use App\Http\Controllers\Controller;
use App\Models\Kelas;
use App\Models\MataPelajaran;
use App\Models\RaporSantri;
use App\Models\Santri;
use Illuminate\Http\Request;

class RaportSantriController extends Controller
{
public function index()
{
$kelas = Kelas::get();
return view('pages.rapor.index', compact('kelas'));
}

public function santri(Kelas $kelas)
{
$santri = Santri::where('kelas_id', $kelas->id)->get();
return view('pages.rapor.santri', compact('santri', 'kelas'));
}
public function nilai(Santri $santri)
{
$rapor = RaporSantri::join('mata_pelajarans', 'rapor_santris.mata_pelajaran_id', '=', 'mata_pelajarans.id')
->where('santri_id', $santri->id)
->get();

$mapel = MataPelajaran::all();

$kelas = Kelas::where('id', $santri->kelas_id)->first();
return view('pages.rapor.nilai', [
'rapor' => $rapor->isEmpty() ? $mapel : $rapor,
'santri' => $santri,
'kelas' => $kelas
]);
}
}
16 changes: 16 additions & 0 deletions app/Http/Controllers/Riwayat/RiwayatController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace App\Http\Controllers\Riwayat;

use App\Http\Controllers\Controller;
use App\Models\ActivityLog;
use Illuminate\Http\Request;

class RiwayatController extends Controller
{
public function index()
{
$riwayat = ActivityLog::with('user')->get();
return view('pages.riwayat.index', compact('riwayat'));
}
}
Loading

0 comments on commit ceeed72

Please sign in to comment.