Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
ArdianS18 committed Jul 15, 2024
2 parents 2d9b03c + 8ad93c3 commit f08ff7f
Show file tree
Hide file tree
Showing 8 changed files with 55 additions and 13 deletions.
3 changes: 3 additions & 0 deletions app/Contracts/Interfaces/ModelHasRfidInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,7 @@ public function exists(mixed $rfid): mixed;

public function activeRfid(): mixed;
public function nonActiveRfid(): mixed;
public function whereSchool($id): mixed;
public function whereNotNull(mixed $column):mixed;
public function whereNull(mixed $column):mixed;
}
3 changes: 1 addition & 2 deletions app/Contracts/Repositories/ClassroomRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ public function paginate() : mixed

public function whereInSchoolYears($schoolYears)
{
$schoolYearIds = $schoolYears->pluck('id')->toArray();
return $this->model->query()->whereIn('school_year_id', $schoolYearIds)->get();
return $this->model->query()->where('school_year_id', $schoolYears)->get();
}
}
15 changes: 15 additions & 0 deletions app/Contracts/Repositories/ModelHasRfidRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,4 +65,19 @@ public function exists(mixed $rfid): mixed
{
return $this->model->query()->where('rfid', $rfid)->exists();
}

public function whereSchool($id): mixed
{
return $this->model->query()->where('school_id', $id)->get();
}

public function whereNotNull(mixed $column):mixed
{
return $this->model->query()->whereNotNull($column)->get();
}

public function whereNull(mixed $column):mixed
{
return $this->model->query()->whereNull($column)->get();
}
}
2 changes: 1 addition & 1 deletion app/Contracts/Repositories/SchoolYearRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public function where(mixed $data): mixed

public function whereSchool(mixed $id): mixed
{
return $this->model->query()->where('school_id', $id)->latest()->paginate(10);
return $this->model->query()->where('school_id', $id)->get();
}

public function active(mixed $id): mixed
Expand Down
5 changes: 4 additions & 1 deletion app/Http/Controllers/ModelHasRfidController.php
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,11 @@ public function store(StoreModelHasRfidRequest $request)
{
$exist = $this->service->check($request);

$data = $request->validated();
$data['school_id'] = auth()->user()->school->id;

if ($exist) {
$this->modelHasRfid->store($request->validated());
$this->modelHasRfid->store($data);
return redirect()->back()->with('success', 'Berhasil menambahkan kartu rfid');
} else {
return redirect()->back()->with('error', 'Kartu rfid tidak valid');
Expand Down
25 changes: 23 additions & 2 deletions app/Http/Controllers/SchoolController.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,12 @@
namespace App\Http\Controllers;

use App\Contracts\Interfaces\CityInterface;
use App\Contracts\Interfaces\ClassroomInterface;
use App\Contracts\Interfaces\EmployeeInterface;
use App\Contracts\Interfaces\ModelHasRfidInterface;
use App\Contracts\Interfaces\ProvinceInterface;
use App\Contracts\Interfaces\SchoolInterface;
use App\Contracts\Interfaces\SchoolYearInterface;
use App\Contracts\Interfaces\SubDistrictInterface;
use App\Contracts\Interfaces\VillageInterface;
use App\Models\School;
Expand All @@ -22,8 +25,11 @@ class SchoolController extends Controller
private SubDistrictInterface $subdistrict;
private VillageInterface $village;
private EmployeeInterface $employee;
private ClassroomInterface $classroom;
private SchoolYearInterface $schoolYear;
private ModelHasRfidInterface $modelHasRfid;

public function __construct(SchoolInterface $school, SchoolService $service, ProvinceInterface $province, CityInterface $city, SubDistrictInterface $subdistrict, VillageInterface $village, EmployeeInterface $employee)
public function __construct(SchoolInterface $school, SchoolService $service, ProvinceInterface $province, CityInterface $city, SubDistrictInterface $subdistrict, VillageInterface $village, EmployeeInterface $employee, ClassroomInterface $classroom, SchoolYearInterface $schoolYear, ModelHasRfidInterface $modelHasRfid)
{
$this->school = $school;
$this->service = $service;
Expand All @@ -32,6 +38,9 @@ public function __construct(SchoolInterface $school, SchoolService $service, Pro
$this->subdistrict = $subdistrict;
$this->village = $village;
$this->employee = $employee;
$this->classroom = $classroom;
$this->schoolYear = $schoolYear;
$this->modelHasRfid = $modelHasRfid;
}

/**
Expand Down Expand Up @@ -75,7 +84,19 @@ public function show($slug)
{
$school = $this->school->showWithSlug($slug);
$teachers = $this->employee->getTeacherBySchool($school->id);
return view('admin.pages.list-school.detail', compact('school', 'teachers'));
$schoolYears = $this->schoolYear->whereSchool($school->id);
$rfids = $this->modelHasRfid->whereSchool($school->id);
$activeRfids = $this->modelHasRfid->whereNotNull('model_type');
$nonactiveRfids = $this->modelHasRfid->whereNull('model_type');
$schoolYear = $this->schoolYear->active($school->id);

$classrooms = 0;
// Loop untuk menghitung jumlah classrooms dari setiap schoolYear
foreach ($schoolYears as $schoolYear) {
$classrooms += $this->classroom->whereInSchoolYears($schoolYear->school_year)->count();
}

return view('admin.pages.list-school.detail', compact('school', 'teachers', 'classrooms', 'rfids', 'activeRfids', 'nonactiveRfids', 'schoolYear'));
}

/**
Expand Down
1 change: 1 addition & 0 deletions app/Http/Requests/StoreModelHasRfidRequest.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public function rules(): array
{
return [
'rfid' => 'required|unique:model_has_rfids,rfid',
'school_id' => 'nullable',
];
}

Expand Down
14 changes: 7 additions & 7 deletions resources/views/admin/pages/list-school/detail.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
<div class="d-flex align-items-center mb-5">
<img class="card-img-top img-responsive me-3" style="max-height:80px; width: auto;"
src="{{ asset('storage/'. $school->image) }}"
alt="Card image cap">
alt="{{ $school->user->name }}">
<div class="d-flex flex-column flex-sm-row justify-content-between w-100 ms-3">
<div>
<h3 class="mb-1">{{ $school->user->name }}</h3>
<span class="badge font-medium bg-light-primary text-primary">{{ $school->type }}</span>
</div>
<div>
<h5 class="mb-1">Tahun Ajaran</h5>
<h5>2023/2024</h5>
<h5>{{ $schoolYear->school_year }}</h5>
</div>
</div>
</div>
Expand Down Expand Up @@ -114,7 +114,7 @@
</div>
</div>
<div class="bg-light-warning text-warning d-inline-block px-3 py-1 fs-8 rounded">
18
{{ $classrooms }}
</div>
</div>
</div>
Expand All @@ -136,7 +136,7 @@
</div>
</div>
<div class="bg-light-success text-success d-inline-block px-3 py-1 fs-8 rounded">
18
0
</div>
</div>
</div>
Expand Down Expand Up @@ -175,19 +175,19 @@
<div class="rfid-container d-flex flex-wrap justify-content-center justify-content-md-between mx-md-5">
<div class="rfid-item mb-3 text-center">
<div class="bg-light-primary text-primary d-inline-block px-4 py-4 fs-8 rounded fixed-size-div">
<b>100</b>
<b>{{ $rfids->count() }}</b>
</div>
<h5>Jumlah RFID</h5>
</div>
<div class="rfid-item mb-3 text-center">
<div class="bg-light-success text-success d-inline-block px-4 py-4 fs-8 rounded fixed-size-div">
<b>50</b>
<b>{{ $activeRfids->count() }}</b>
</div>
<h5>RFID Aktif</h5>
</div>
<div class="rfid-item mb-3 text-center">
<div class="bg-light-danger text-danger d-inline-block px-4 py-4 fs-8 rounded fixed-size-div">
<b>100</b>
<b>{{ $nonactiveRfids->count() }}</b>
</div>
<h5>RFID Tidak Aktif</h5>
</div>
Expand Down

0 comments on commit f08ff7f

Please sign in to comment.