Skip to content

Commit

Permalink
full feature admin and user
Browse files Browse the repository at this point in the history
  • Loading branch information
9lan committed Jul 14, 2022
1 parent df03156 commit 349ebaf
Show file tree
Hide file tree
Showing 25 changed files with 743 additions and 50 deletions.
2 changes: 0 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
/node_modules
/public/hot
/public/storage
/public/images/
/storage/*.key
.env
.env.backup
.phpunit.result.cache
Expand Down
9 changes: 8 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,4 +62,11 @@ If you discover a security vulnerability within Laravel, please send an e-mail t
## License

The Laravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
# Perpus

# How To Run

```
php artisan storage:link
php artisan migrate
php artisan serve
```
54 changes: 42 additions & 12 deletions app/Http/Controllers/BukuController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,41 @@
use Illuminate\Http\Request;
use App\Models\Buku;
use App\Models\RakBuku;
use App\Models\Peminjaman;
use Illuminate\Support\Facades\Storage;

class BukuController extends Controller
{
public function index()
{
$buku = Buku::all();
$rak_buku = RakBuku::all();
return view('admin.list-buku', ['buku' => $buku, 'rak_buku' => $rak_buku]);

if (request()->has('search')) {
$buku = Buku::where('judul', 'LIKE', '%' . request('search') . '%')->get();
}

if (auth()->user()->is_verified == 1) {
return view('user.buku.index', compact('buku', 'rak_buku'));
}

return view('admin.list-buku', compact('buku', 'rak_buku'));
}

public function create(Request $request)
{
$data = new Buku();

if ($request->hasFile('foto')) {
$file = $request->file('foto');
$fileName = $file->getClientOriginalName();
$request->file('foto')->move(public_path('images'), $fileName);
$data->foto = $fileName;
$data->foto = $request->file('foto')->store('images');
}

$data->judul = $request->judul;
$data->sinopsis = $request->sinopsis;
$data->penulis = $request->penulis;
$data->denda = $request->denda;
$data->kode_rak = $request->kode_rak;
$data->kode_buku = $request->kode_buku;
$data->rak_buku_id = $request->kode_rak;
$data->status = $request->status;

$data->save();
Expand All @@ -44,18 +52,21 @@ public function findById(Request $request, $id)
$data = Buku::find($id);
$rak_buku = RakBuku::all();

if (auth()->user()->is_verified == 1) {
return view('user.buku.lihat', compact('data', 'rak_buku'));
}

return view('admin.edit-buku', ['data' => $data, 'rak_buku' => $rak_buku]);
}

public function update(Request $request, $id)
{
$data = Buku::findOrFail($id);
$photo_path = public_path('images/' . $data->foto);

if ($request->hasFile('foto')) {
$file = $request->file('foto');
$fileName = $file->getClientOriginalName();
$request->file('foto')->move(public_path('images'), $fileName);
$data->foto = $fileName;
if ($request->hasFile('foto-baru')) {
Storage::delete($data->foto);
$data->foto = $request->file('foto-baru')->store('images');
} else {
$data->foto = $data->foto;
}
Expand All @@ -64,7 +75,7 @@ public function update(Request $request, $id)
$data->sinopsis = $request->sinopsis;
$data->penulis = $request->penulis;
$data->denda = $request->denda;
$data->kode_rak = $request->kode_rak;
$data->rak_buku_id = $request->kode_rak;
$data->kode_buku = $request->kode_buku;
$data->status = $request->status;

Expand All @@ -85,4 +96,23 @@ public function delete(Request $request, $id)

return redirect()->route('admin.list-buku')->with('success', 'Berhasil menghapus data!');
}

public function pinjam(Request $request, $id)
{
date_default_timezone_set('Asia/Jakarta');
$data = Buku::findOrFail($id);
$pinjam = new Peminjaman;

$pinjam->user_id = auth()->user()->id;
$pinjam->buku_id = $data->id;
$pinjam->tanggal_pinjam = date('Y-m-d');
$pinjam->status = $request->status;

$data->status = $request->status;

$pinjam->save();
$data->save();

return redirect()->route('user.buku.index')->with('success', 'Berhasil meminjam buku!');
}
}
29 changes: 29 additions & 0 deletions app/Http/Controllers/ListAnggotaController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
<?php

namespace App\Http\Controllers;
use App\Models\User;

use Illuminate\Http\Request;

class ListAnggotaController extends Controller
{
public function index()
{
$anggota = User::all();
$unverified = User::where('is_verified', 0)->get();

if (request()->has('search')) {
$anggota = User::where('name', 'LIKE', '%' . request('search') . '%')->get();
}

return view('admin.list-anggota.index', compact('anggota', 'unverified'));
}

public function verify()
{
$anggota = User::find(request()->id);
$anggota->is_verified = 1;
$anggota->save();
return back()->with('success', 'Berhasil mengkonfirmasi data!');
}
}
2 changes: 1 addition & 1 deletion app/Http/Controllers/LoginAdminController.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public function authenticate() {
$credentials = request(['email', 'password']);
if (auth()->guard('admin')->attempt($credentials)) {
request()->session()->regenerate();
return redirect()->intended('/');
return redirect()->intended('/admin');
}
return back()->with(['login_error' => 'Email or password is incorrect.']);
}
Expand Down
84 changes: 84 additions & 0 deletions app/Http/Controllers/PeminjamanController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Buku;
use App\Models\User;
use App\Models\Admin;
use App\Models\Peminjaman;
use App\Models\Pengembalian;

class PeminjamanController extends Controller
{
public function index()
{
$buku = Buku::all();
$anggota = User::all();
$petugas = Admin::all();
$peminjaman = Peminjaman::where('status', '!=', 'tersedia')->get();
$booking = Peminjaman::where('status', 'booking')->get();

return view('admin.peminjaman.index', compact('buku', 'anggota', 'petugas', 'peminjaman', 'booking'));
}

public function verify()
{
date_default_timezone_set('Asia/Jakarta');
$dt = Peminjaman::find(request()->id);
$buku = Buku::findOrFail($dt->buku_id);

$buku->status = 'dipinjam';
$dt->admin_id = auth()->user()->id;
$dt->status = request()->status;
$dt->tanggal_kembali = date_format(date_create(request()->tanggal_kembali), 'Y-m-d');

$buku->save();
$dt->save();

return back()->with('success', 'Buku dipinjamkan');
}

public function findById(Request $request, $id)
{
$dt = Peminjaman::findOrFail($id);

return view('admin.peminjaman.view', compact('dt'));
}

public function update(Request $request, $id)
{
date_default_timezone_set('Asia/Jakarta');
$peminjaman = Peminjaman::findOrFail($id);
$buku = Buku::findOrFail($peminjaman->buku_id);

$pengembalian = new Pengembalian();

$buku->status = 'tersedia';

$pengembalian->tanggal_kembali = date_format(date_create(request()->tanggal_kembali), 'Y-m-d');
$pengembalian->jatuh_tempo = $peminjaman->tanggal_kembali;

$jumlah_hari = date_diff(date_create($peminjaman->tanggal_kembali), date_create(request()->tanggal_kembali))->days;

if ($jumlah_hari > 0) {
$pengembalian->jumlah_hari = $jumlah_hari;
$pengembalian->total_denda = $jumlah_hari * $peminjaman->buku->denda;
$pengembalian->status = 'Denda';
} else {
$pengembalian->jumlah_hari = 0;
$pengembalian->total_denda = 0;
$pengembalian->status = 'Tepat Waktu';
}

$pengembalian->buku_id = $peminjaman->buku->id;
$pengembalian->admin_id = auth()->user()->id;
$pengembalian->user_id = $peminjaman->user->id;

$pengembalian->save();
$buku->save();
$peminjaman->delete();

return redirect()->route('admin.peminjaman')->with('success', 'Buku dipinjamkan');
}
}
34 changes: 34 additions & 0 deletions app/Http/Controllers/PengembalianController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Pengembalian;

class PengembalianController extends Controller
{
public function index()
{
$data = Pengembalian::all();
$verif_status = Pengembalian::where('status', '=', 'denda')->get();

if (auth()->user()->is_verified == 1) {
$data = Pengembalian::where('user_id', '=', auth()->user()->id)->get();
return view('user.denda.index', compact('data', 'verif_status'));
}
return view('admin.pengembalian.index', compact('data', 'verif_status'));
}

public function verify()
{
$dt = Pengembalian::find(request()->id);

$dt->status = request()->status;
$dt->jumlah_hari = 0;
$dt->total_denda = 0;

$dt->save();

return back()->with('success', 'Denda terbayar');
}
}
5 changes: 5 additions & 0 deletions app/Models/Buku.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,9 @@
class Buku extends Model
{
use HasFactory;

public function rak_buku()
{
return $this->belongsTo(RakBuku::class);
}
}
19 changes: 19 additions & 0 deletions app/Models/Peminjaman.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,30 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;
use App\Models\Admin;
use App\Models\Buku;

class Peminjaman extends Model
{
use HasFactory;

protected $table = 'peminjamen';
protected $fillable = ['tanggal_pinjam', 'tanggal_kembali', 'id_petugas', 'id_anggota', 'kode_buku', 'status'];

public function user()
{
return $this->belongsTo(User::class);
}

public function admin()
{
return $this->belongsTo(Admin::class);
}

public function buku()
{
return $this->belongsTo(Buku::class);
}

}
18 changes: 17 additions & 1 deletion app/Models/Pengembalian.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,30 @@

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use App\Models\User;
use App\Models\Admin;
use App\Models\Buku;

class Pengembalian extends Model
{
use HasFactory;

protected $table = 'pengembalian';
protected $table = 'pengembalians';
protected $fillable = ['tanggal_kembali', 'id_petugas', 'id_anggota', 'kode_buku', 'status'];


public function user()
{
return $this->belongsTo(User::class);
}

public function admin()
{
return $this->belongsTo(Admin::class);
}

public function buku()
{
return $this->belongsTo(Buku::class);
}
}
6 changes: 3 additions & 3 deletions database/migrations/2022_07_08_091150_create_bukus_table.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ public function up()
{
Schema::create('bukus', function (Blueprint $table) {
$table->id();
$table->string('kode_buku', 20)->unique()->nullable();
$table->integer('rak_buku_id')->nullable();
$table->string('judul', 100)->nullable();
$table->text('sinopsis', 100)->nullable();
$table->string('penulis', 100)->nullable();
$table->string('kode_rak', 12)->nullable();
$table->string('kode_buku', 12)->nullable();
$table->text('foto')->nullable();
$table->enum('status', ['tersedia', 'dipinjam'])->default('tersedia')->nullable();
$table->enum('status', ['tersedia', 'booking', 'dipinjam'])->default('tersedia')->nullable();
$table->integer('denda')->default(0)->nullable();
$table->timestamps();
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ public function up()
Schema::create('peminjamen', function (Blueprint $table) {
$table->id();
$table->date('tanggal_pinjam');
$table->date('tanggal_kembali');
$table->integer('id_petugas');
$table->integer('id_anggota');
$table->string('kode_buku', 20);
$table->enum('status', ['dipinjam', 'kembali']);
$table->date('tanggal_kembali')->nullable();
$table->integer('admin_id')->nullable();
$table->integer('user_id');
$table->integer('buku_id');
$table->enum('status', ['dipinjam', 'booking', 'tersedia'])->default('tersedia');
$table->timestamps();
});
}
Expand Down
Loading

0 comments on commit 349ebaf

Please sign in to comment.