Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
alfian8752 committed Jul 16, 2024
2 parents 8c02619 + 34ea503 commit 4b10449
Show file tree
Hide file tree
Showing 26 changed files with 419 additions and 97 deletions.
2 changes: 1 addition & 1 deletion app/Contracts/Interfaces/AttendanceInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,5 @@

interface AttendanceInterface extends GetInterface, StoreInterface, UpdateInterface, ShowInterface, DeleteInterface, PaginateInterface, WhereSchoolInterface
{
//
public function AttendanceChart(mixed $id, mixed $year, mixed $month) : mixed;
}
6 changes: 4 additions & 2 deletions app/Contracts/Interfaces/SemesterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@
use App\Contracts\Interfaces\Eloquent\ShowInterface;
use App\Contracts\Interfaces\Eloquent\StoreInterface;
use App\Contracts\Interfaces\Eloquent\UpdateInterface;
use App\Contracts\Interfaces\Eloquent\WhereInterface;

interface SemesterInterface extends GetInterface, StoreInterface {
//
interface SemesterInterface extends GetInterface, StoreInterface
{
public function whereSchool(mixed $id): mixed;
}
9 changes: 9 additions & 0 deletions app/Contracts/Repositories/AttendanceRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,13 @@ public function whereSchool(mixed $id): mixed
{
return $this->model->query()->whereRelation('classroomStudent.classroom.schoolYear.school', 'id', $id)->latest()->paginate(10);
}

public function AttendanceChart(mixed $id, mixed $year, mixed $month): mixed
{
return $this->model->query()
->whereRelation('classroomStudent.classroom.schoolYear', 'school_id', $id)
->whereYear('created_at', $year)
->whereMonth('created_at', $month)
->count();
}
}
2 changes: 1 addition & 1 deletion app/Contracts/Repositories/ClassroomRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public function paginate() : mixed

public function whereInSchoolYears($schoolYears)
{
return $this->model->query()->whereIn('school_year_id', $schoolYears)->get();
return $this->model->query()->where('school_year_id', $schoolYears)->get();
}

public function countClass(mixed $id): mixed
Expand Down
7 changes: 6 additions & 1 deletion app/Contracts/Repositories/SemesterRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,16 @@ public function __construct(Semester $semester)

public function get(): mixed
{
return $this->model->query()->where('school_id', auth()->user()->school->id)->get();
return $this->model->query()->where('school_id', auth()->user()->school->id)->orderBy('created_at', 'desc')->get();
}

public function store(array $data): mixed
{
return $this->model->query()->create($data);
}

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->where('school_id', $id)->latest()->firstOrFail();
}
}
23 changes: 23 additions & 0 deletions app/Http/Controllers/AttendanceMasterController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

namespace App\Http\Controllers;

use App\Contracts\Interfaces\ModelHasRfidInterface;
use Illuminate\Http\Request;

class AttendanceMasterController extends Controller
{
private ModelHasRfidInterface $modelHasRfid;

public function __construct(ModelHasRfidInterface $modelHasRfid) {
$this->modelHasRfid = $modelHasRfid;
}

public function index() {
return view('school.pages.test.attendance');
}

public function check(Request $request) {

}
}
6 changes: 3 additions & 3 deletions app/Http/Controllers/MapleController.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function store(StoreMapleRequest $request)
{
$data = $this->service->store($request);
$this->maple->store($data);
return redirect()->back()->with('success', 'Berhasil menambahkan mapel pelajaram');
return redirect()->back()->with('success', 'Berhasil menambahkan mata pelajaran');
}

/**
Expand All @@ -73,7 +73,7 @@ public function update(UpdateMapleRequest $request, Maple $maple)
{
$data = $this->service->update($maple, $request);
$this->maple->update($maple->id, $data);
return redirect()->back()->with('success', 'Berhasil memperbarui mapel pelajaram');
return redirect()->back()->with('success', 'Berhasil memperbarui mata pelajaran');
}

/**
Expand All @@ -82,6 +82,6 @@ public function update(UpdateMapleRequest $request, Maple $maple)
public function destroy(Maple $maple)
{
$this->maple->delete($maple->id);
return redirect()->back()->with('success', 'Berhasil menghapus mapel pelajaran');
return redirect()->back()->with('success', 'Berhasil menghapus mata pelajaran');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/SchoolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ public function update(UpdateSchoolRequest $request, School $school)
{
$data = $this->service->update($school, $request);
$this->school->update($school->id, $data);
return to_route('school-admin.index')->with('success', 'Berhasil memperbarui sekolah');
return to_route('settings-information.index')->with('success', 'Berhasil memperbarui sekolah');
}

/**
Expand Down
30 changes: 18 additions & 12 deletions app/Http/Controllers/SchoolDashboardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,19 @@

namespace App\Http\Controllers;

use App\Contracts\Interfaces\AttendanceInterface;
use App\Contracts\Interfaces\ClassroomInterface;
use App\Contracts\Interfaces\EmployeeInterface;
use App\Contracts\Interfaces\MapleInterface;
use App\Contracts\Interfaces\ModelHasRfidInterface;
use App\Contracts\Interfaces\SchoolInterface;
use App\Contracts\Interfaces\SchoolYearInterface;
use App\Contracts\Interfaces\SemesterInterface;
use App\Contracts\Interfaces\StudentInterface;
use App\Http\Requests\StoreModelHasRfidRequest;
use App\Models\School;
use App\Services\ModelHasRfidService;
use App\Services\SchoolChartService;
use Illuminate\Http\Request;
use PhpParser\Node\Expr\FuncCall;

Expand All @@ -20,26 +23,34 @@ class SchoolDashboardController extends Controller
private SchoolInterface $school;
private SchoolYearInterface $schoolYear;
private ModelHasRfidInterface $rfid;

private EmployeeInterface $employee;
private StudentInterface $student;
private MapleInterface $maple;
private ClassroomInterface $classroom;
private SemesterInterface $semester;
private AttendanceInterface $attendance;

private SchoolChartService $schoolChart;

public function __construct(SchoolInterface $school,
SchoolYearInterface $schoolYear, ModelHasRfidInterface $rfid, ClassroomInterface $classroom)
public function __construct(SchoolInterface $school, SchoolYearInterface $schoolYear,
ModelHasRfidInterface $rfid, ClassroomInterface $classroom, SemesterInterface $semester,
SchoolChartService $schoolChart, AttendanceInterface $attendance)
{
$this->school = $school;
$this->schoolYear = $schoolYear;
$this->rfid = $rfid;
$this->classroom = $classroom;
$this->semester = $semester;
$this->attendance = $attendance;
$this->schoolChart = $schoolChart;
}

public function index()
{
$school = $this->school->whereUserId(auth()->user()->id);
$classrooms = $this->classroom->countClass(auth()->user()->school->id);
return view('school.pages.dashboard', compact('school', 'classrooms'));
$schoolYear = $this->schoolYear->active(auth()->user()->school->id);
$semester = $this->semester->whereSchool(auth()->user()->school->id);
$attendanceChart = $this->schoolChart->ChartAttendance($this->attendance);
// dd($attendanceChart);
return view('school.pages.dashboard', compact('school', 'classrooms', 'schoolYear', 'semester', 'attendanceChart'));
}

public function show()
Expand All @@ -55,9 +66,4 @@ public function edit()
$school = $this->school->showWithSlug(auth()->user()->slug);
return view('school.pages.settings.update-information', compact('school'));
}

public function update()
{
//
}
}
3 changes: 2 additions & 1 deletion app/Http/Requests/StoreSchoolRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public function messages(): array
'city.required' => 'Kabupaten atau kota wajib di isi',
'sub_district_id.required' => 'Kecamatan wajib di isi',
'type.required' => 'Tipe sekolah wajib di isi',
'level.required' => 'Jenjang wajib di isi'
'level.required' => 'Jenjang wajib di isi',
'accreditation.required' => 'Akreditasi harus diisi',
];
}
}
31 changes: 16 additions & 15 deletions app/Http/Requests/UpdateSchoolRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ public function authorize(): bool
public function rules(): array
{
return [
'npsn' => 'required|min:8',
'phone_number' => 'required|min:15',
'image' => 'required',
'pas_code' => 'required|min:10',
'name' => 'required',
'email' => 'required|email',
'npsn' => 'required|max:8',
'phone_number' => 'required|max:15',
'image' => 'nullable|mimes:png,jpg,jpeg',
'pas_code' => 'required|max:10',
'address' => 'required',
'head_school' => 'required',
'nip' => 'required',
'website_school' => 'nullable',
'website_school' => 'nullable|url',
'description' => 'nullable',
'province' => 'required',
'city' => 'required',
'sub_district' => 'required',
'accreditation' => 'required',
];
}

Expand All @@ -45,19 +45,20 @@ public function rules(): array
public function messages(): array
{
return [
'name.required' => 'Nama sekolah wajib diisi.',
'email.required' => 'Email sekolah wajib diisi.',
'email.email' => 'Email sekolah tidak valid.',
'npsn.required' => 'NPSN wajib diisi.',
'npsn.min' => 'NPSN harus terdiri dari minimal 8 karakter.',
'npsn.max' => 'NPSN harus terdiri dari maximal :max karakter.',
'phone_number.required' => 'Nomor telepon wajib diisi.',
'phone_number.min' => 'Nomor telepon harus terdiri dari minimal 15 karakter.',
'image.required' => 'Gambar wajib diunggah.',
'phone_number.max' => 'Nomor telepon harus terdiri dari maximal :max karakter.',
'image.mimes' => 'Gambar harus berekstensi png, jpg atau jpeg.',
'pas_code.required' => 'Kode PAS wajib diisi.',
'pas_code.min' => 'Kode PAS harus terdiri dari minimal 10 karakter.',
'pas_code.max' => 'Kode PAS harus terdiri dari maximal :max karakter.',
'address.required' => 'Alamat wajib diisi.',
'head_school.required' => 'Nama kepala sekolah wajib diisi.',
'nip.required' => 'NIP wajib diisi.',
'province.required' => 'Profinsi wajib di isi',
'city.required' => 'Kabupaten atau kota wajib di isi',
'sub_district.required' => 'Kecamatan wajib di isi'
'accreditation.required' => 'Akreditasi harus diisi',
];
}
}
29 changes: 29 additions & 0 deletions app/Services/AttendanceService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Services;

use App\Contracts\Interfaces\AttendanceRuleInterface;
use App\Contracts\Interfaces\ModelHasRfidInterface;
use App\Contracts\Interfaces\StudentInterface;
use App\Http\Requests\StoreAttendanceRequest;
use Carbon\Carbon;

class AttendanceService
{
private ModelHasRfidInterface $modelHasRfid;
private AttendanceRuleInterface $attendanceRule;
private StudentInterface $student;

public function __construct(ModelHasRfidInterface $modelHasRfid, StudentInterface $student, AttendanceRuleInterface $attendanceRule)
{
$this->modelHasRfid = $modelHasRfid;
$this->student = $student;
$this->attendanceRule = $attendanceRule;
}

public function store(StoreAttendanceRequest $request): array|bool
{
$data = $request->validated();
return $data;
}
}
39 changes: 39 additions & 0 deletions app/Services/SchoolChartService.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

namespace App\Services;

use App\Contracts\Interfaces\AttendanceInterface;
use Carbon\Carbon;

class SchoolChartService
{
private AttendanceInterface $attendance;

public function __construct(AttendanceInterface $attendance)
{
$this->attendance = $attendance;
}

public function ChartAttendance(AttendanceInterface $attendance)
{
$Curentyear = Carbon::now()->year;
$Curentmonth = Carbon::now()->month;

$grafikDataCollection = [];

for($month = 1; $month <= 12; $month++){
$date = Carbon::createFromDate($Curentyear, $month, 1);
$yearMonth = $date->isoFormat('MMMM');
$attendance = $this->attendance->AttendanceChart(auth()->user()->school->id, $Curentyear, $month);

$grafikDataCollection[] = [
'year' => $Curentyear,
'month' => $yearMonth,
'attendance' => $attendance
];
}
$data = array_values($grafikDataCollection);

return $data;
}
}
17 changes: 6 additions & 11 deletions app/Services/SchoolService.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,20 +58,15 @@ public function update(School $school, UpdateSchoolRequest $request): array|bool
'email' => $data['email'],
'password' => Hash::make($data['npsn']),
];
$user = $this->user->update($school->user_id ,$dataUser);
$user->assignRole(RoleEnum::SCHOOL->value);

$old_image = $school->image;
$image = "";
$this->user->update($school->user_id, $dataUser);

if ($request->hasFile('image')) {
if (file_exists(public_path($old_image))) {
unlink(public_path($old_image));
}
$image = $this->upload(UploadDiskEnum::LOGO->value, $request->image);
if ($request->hasFile('image') && $request->file('image')->isValid()) {
$this->remove($school->image);
$data['image'] = $request->file('image')->store(UploadDiskEnum::TEACHER->value, 'public');
} else {
$data['image'] = $school->image;
}

$data['image'] = $image ?: $old_image;
return $data;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
<?php

use App\Enums\SemesterEnum;
use App\Traits\Migrations\HasForeign;
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

return new class extends Migration
{
use HasForeign;

/**
* Run the migrations.
*/
Expand All @@ -15,7 +18,7 @@ public function up(): void
Schema::create('semesters', function (Blueprint $table) {
$table->id();
$table->string('type')->enum([SemesterEnum::GANJIL, SemesterEnum::GENAP]);
$table->foreignId('school_id')->constrained()->cascadeOnDelete()->cascadeOnUpdate();
$this->addForeignId($table,'school_id');
$table->timestamps();
});
}
Expand Down
2 changes: 1 addition & 1 deletion database/seeders/SchoolYearSeeder.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public function run(): void
],
[
'school_year' => '2023/2024',
'active' => '1',
'active' => '0',
],
[
'school_year' => '2024/2025',
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 4b10449

Please sign in to comment.