melengkapi dan memeperbaiki fungsi-fungsi

parent 6aa84757
......@@ -27,7 +27,7 @@ class HomeController extends Controller
public function index()
{
if (Laratrust::hasRole('admin')) return $this->adminDashboard();
if (Laratrust::hasRole('member')) return $this->memberDashboard();
if (Laratrust::hasRole('customer')) return $this->customerDashboard();
if (Laratrust::hasRole('deliver')) return $this->deliverDashboard();
if (Laratrust::hasRole('chef')) return $this->chefDashboard();
if (Laratrust::hasRole('manager')) return $this->managerDashboard();
......@@ -58,9 +58,9 @@ protected function adminDashboard()
{
return view('dashboard.admin');
}
protected function memberDashboard()
protected function customerDashboard()
{
$borrowLogs = Auth::user()->borrowLogs()->borrowed()->get();
return view('dashboard.member', compact('borrowLogs'));
return view('dashboard.customer', compact('borrowLogs'));
}
}
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Pesanan as pesanan;
use App\Http\Requests\StorePesananRequest;
use App\Http\Requests\UpdatePesananRequest;
use Yajra\Datatables\Html\Builder;
use Yajra\Datatables\Datatables;
class PesananController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Http\Response
*/
public function index(Request $request, Builder $htmlBuilder)
{
if ($request->ajax()) {
$books = Book::with('author');
return Datatables::of($books)
->addColumn('stock', function($book){
return $book->stock;
})
->addColumn('action', function($book){
return view('datatable._action', [
'model' => $book,
'form_url' => route('books.destroy', $book->id),
'edit_url' => route('books.edit', $book->id),
'confirm_message' => 'Yakin ingin menghapus ' . $book->title . '?',
]);
})->make(true);
}
$html = $htmlBuilder
->addColumn(['data' => 'title', 'name'=>'title', 'title'=>'Jenis Makanan'])
->addColumn(['data' => 'stock', 'name'=>'amount', 'title'=>'Stock'])
->addColumn(['data' => 'harga', 'name'=>'harga', 'title'=>'harga'])
->addColumn(['data' => 'author.name', 'name'=>'author.name', 'title'=>'Pemesan'])
->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'Action', 'orderable'=>false, 'searchable'=>false]);
return view('books.index')->with(compact('html'));
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create()
{
return view('books.create');
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function borrow($id)
{
try {
$book = Book::findOrFail($id);
Auth::user()->borrow($book);
Session::flash("flash_notification", [
"level"=>"success",
"message"=>"Berhasil memesan $book->title"
]);
} catch (BookException $e) {
Session::flash("flash_notification", [
"level" => "danger",
"message" => $e->getMessage()
]);
} catch (ModelNotFoundException $e) {
Session::flash("flash_notification", [
"level" => "danger",
"message" => "Makanan tidak ditemukan."
]);
}
return redirect('/');
}
public function store(StoreBookRequest $request)
{
$book = Book::create($request->except('cover'));
// isi field cover jika ada cover yang diupload
if ($request->hasFile('cover')) {
// Mengambil file yang diupload
$uploaded_cover = $request->file('cover');
// mengambil extension file
$extension = $uploaded_cover->getClientOriginalExtension();
// membuat nama file random berikut extension
$filename = md5(time()) . '.' . $extension;
// menyimpan cover ke folder public/img
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img';
$uploaded_cover->move($destinationPath, $filename);
// mengisi field cover di book dengan filename yang baru dibuat
$book->cover = $filename;
$book->save();
}
Session::flash("flash_notification", [
"level"=>"success",
"message"=>"Berhasil menyimpan $book->title"
]);
return redirect()->route('books.index');
}
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($id)
{
//
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function edit($id)
{
$book = Book::find($id);
return view('books.edit')->with(compact('book'));
}
/**
* Update the specified resource in storage.
*
* @param \Illuminate\Http\Request $request
* @param int $id
* @return \Illuminate\Http\Response
*/
public function update(UpdateBookRequest $request, $id)
{
$book = Book::find($id);
if(!$book->update($request->all())) return redirect()->back();
if ($request->hasFile('cover')) {
// menambil cover yang diupload berikut ekstensinya
$filename = null;
$uploaded_cover = $request->file('cover');
$extension = $uploaded_cover->getClientOriginalExtension();
// membuat nama file random dengan extension
$filename = md5(time()) . '.' . $extension;
$destinationPath = public_path() . DIRECTORY_SEPARATOR . 'img';
// memindahkan file ke folder public/img
$uploaded_cover->move($destinationPath, $filename);
// hapus cover lama, jika ada
if ($book->cover) {
$old_cover = $book->cover;
$filepath = public_path() . DIRECTORY_SEPARATOR . 'img'
. DIRECTORY_SEPARATOR . $book->cover;
try {
File::delete($filepath);
} catch (FileNotFoundException $e) {
// File sudah dihapus/tidak ada
}
}
// ganti field cover dengan cover yang baru
$book->cover = $filename;
$book->save();
}
Session::flash("flash_notification", [
"level"=>"success",
"message"=>"Berhasil menyimpan $book->title"
]);
return redirect()->route('books.index');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function destroy(Request $request, $id)
{
$book = Book::find($id);
$cover = $book->cover;
if(!$book->delete()) return redirect()->back();
// handle hapus buku via ajax
if ($request->ajax()) return response()->json(['id' => $id]);
// hapus cover lama, jika ada
if ($cover) {
$old_cover = $book->cover;
$filepath = public_path() . DIRECTORY_SEPARATOR . 'img'
. DIRECTORY_SEPARATOR . $book->cover;
try {
File::delete($filepath);
} catch (FileNotFoundException $e) {
// File sudah dihapus/tidak ada
}
}
Session::flash("flash_notification", [
"level"=>"success",
"message"=>"daftar berhasil dihapus"
]);
return redirect()->route('books.index');
}
public function returnBack($book_id)
{
$borrowLog = BorrowLog::where('user_id', Auth::user()->id)
->where('book_id', $book_id)
->where('is_returned', 0)
->first();
if ($borrowLog) {
$borrowLog->is_returned = true;
$borrowLog->save();
Session::flash("flash_notification", [
"level" => "success",
"message" => "Berhasil mengembalikan " . $borrowLog->book->title
]);
}
return redirect('/home');
}
public function export()
{
return view('books.export');
}
public function exportPost(Request $request)
{
// validasi
$this->validate($request, [
'author_id'=>'required',
'type'=>'required|in:pdf,xls'
], [
'author_id.required'=>'Anda belum registrasi. silahkan registrasi terlebih dahulu.'
]);
$books = Book::whereIn('id', $request->get('author_id'))->get();
$handler = 'export' . ucfirst($request->get('type'));
return $this->$handler($books);
}
private function exportPdf($books)
{
$pdf = PDF::loadview('pdf.books', compact('books'));
return $pdf->download('books.pdf');
}
}
......@@ -19,7 +19,7 @@ class pegawaiController extends Controller
public function index(Request $request, Builder $htmlBuilder)
{
if ($request->ajax()) {
$pegawais = pegawai::with('author');
$pegawais = Pegawai::select(['id','name','alamat','umur','golongan']);
return Datatables::of($pegawais)
->addColumn('stock', function($pegawai){
return $pegawai->stock;
......@@ -27,8 +27,8 @@ class pegawaiController extends Controller
->addColumn('action', function($pegawai){
return view('datatable._action', [
'model' => $pegawai,
'form_url' => route('pegawais.destroy', $pegawai->id),
'edit_url' => route('pegawais.edit', $pegawai->id),
'form_url' => route('pegawai.destroy', $pegawai->id),
'edit_url' => route('pegawai.edit', $pegawai->id),
'confirm_message' => 'Yakin ingin menghapus ' . $pegawai->name . '?',
]);
......
<?php
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class UpdatePesananRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return false;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
//
];
}
}
......@@ -6,6 +6,6 @@ use Illuminate\Database\Eloquent\Model;
class Pegawai extends Model
{
protected $table = "pegawai";
protected $fillable = ['name','alamat','umur' ,'golongan'];
//
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePesananTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pesanan', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('alamat');
$table->string('umur');
$table->string('golongan');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
//
}
}
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
class CreatePegawaisTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('pegawais', function (Blueprint $table) {
$table->increments('id');
$table->string('name');
$table->string('alamat');
$table->string('umur');
$table->string('golongan');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::drop('pegawais');
}
}
......@@ -7,28 +7,81 @@ class UsersSeeder extends Seeder
public function run()
{
// Membuat role admin
$adminRole = new Role();
$adminRole->name = "admin";
$adminRole->display_name = "Admin";
$adminRole->save();
// Membuat role member
$memberRole = new Role();
$memberRole->name = "member";
$memberRole->display_name = "Member";
$memberRole->save();
// Membuat sample admin
$admin = new User();
$admin->name = 'Admin Pizza Andaliman';
$admin->email = 'admin@gmail.com';
$admin->password = bcrypt('admin');
$admin->save();
$admin->attachRole($adminRole);
// Membuat sample member
$member = new User();
$member->name = "Sample Member";
$member->email = 'nicolas@gmail.com';
$member->password = bcrypt('nikolas');
$member->save();
$member->attachRole($memberRole);
$adminRole = new Role();
$adminRole->name = "admin";
$adminRole->display_name = "Admin";
$adminRole->save();
// Membuat role customer
$customerRole = new Role();
$customerRole->name = "customer";
$customerRole->display_name = "Customer";
$customerRole->save();
// Membuat role chef
$chefRole = new Role();
$chefRole->name = "chef";
$chefRole->display_name = "Chef";
$chefRole->save();
// Membuat role deliver
$deliverRole = new Role();
$deliverRole->name = "deliver";
$deliverRole->display_name = "Deliver";
$deliverRole->save();
// Membuat role manager
$managerRole = new Role();
$managerRole->name = "manager";
$managerRole->display_name = "Manager";
$managerRole->save();
// Membuat sample admin
$admin = new User();
$admin->name = 'Admin';
$admin->email = 'admin@gmail.com';
$admin->password = bcrypt('admin');
$admin->save();
$admin->attachRole($adminRole);
// Membuat sample customer
$customer = new User();
$customer->name = "";
$customer->email = 'nicolas@gmail.com';
$customer->password = bcrypt('nikolas');
$customer->save();
$customer->attachRole($customerRole);
// Membuat sample chef
$chef = new User();
$chef->name = 'Chef';
$chef->email = 'chef@gmail.com';
$chef->password = bcrypt('chef');
$chef->save();
$chef->attachRole($chefRole);
// Membuat sample deliver
$deliver = new User();
$deliver->name = 'Deliver';
$deliver->email = 'deliver@gmail.com';
$deliver->password = bcrypt('deliver');
$deliver->save();
$deliver->attachRole($deliverRole);
// Membuat sample manager
$manager = new User();
$manager->name = 'Manager';
$manager->email = 'foodbooking@gmail.com';
$manager->password = bcrypt('pizza');
$manager->save();
$manager->attachRole($managerRole);
}
}
......@@ -10,12 +10,12 @@
<div class="col-md-10">
<ul class="breadcrumb">
<li><a href="{{ url('/home') }}">Dashboard</a></li>
<li><a href="{{ url('/admin/books') }}">Pelanggan</a></li>
<li class="active">Data Pelanggan</li>
<li><a href="{{ url('/admin/books') }}">Pegawai</a></li>
<li class="active">Data Pegawai</li>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Data Pelanggan</h2>
<h2 class="panel-title">Data Pegawai</h2>
</div>
<div class="panel-body">
{!! Form::open(['url' => route('pegawai.store'),
......
......@@ -12,11 +12,11 @@
<ul class="breadcrumb">
<li><a href="{{ url('/home') }}">Dashboard</a></li>
<li><a href="{{ url('/admin/authors') }}">Pelanggan</a></li>
<li class="active">Ubah Pesanan</li>
<li class="active">Ubah Pelanggan</li>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Ubah Pesanan</h2>
<h2 class="panel-title">Ubah Pelanggan</h2>
</div>
<div class="panel-body">
......
......@@ -19,7 +19,7 @@
</div>
<div class="panel-body">
<p> <a class="btn btn-primary" href="{{ route('authors.create') }}">Tambah</a> </p>
<p> <a class="btn btn-primary" href="{{ url('/admin/authors/1/edit') }}">Tambah</a> </p>
{!! $html->table(['class'=>'table-striped']) !!}
</div>
</div>
......
@extends('layouts.app')
@section('content')
<section id="main-content">
<section class="wrapper">
<div class="container">
<div class="row">
<br>
<div class="col-md-10">
<ul class="breadcrumb">
<li><a href="{{ url('/home') }}">PizzaAndaliman</a></li>
<li class="active">PizzaAndaliman</li>
</ul>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">PizzaAndaliman</h2>
</div>
<div class="panel-body">
<p> <a class="btn btn-primary" href="{{ route('authors.create') }}">Tambah</a> </p>
{!! $html->table(['class'=>'table-striped']) !!}
</div>
</div>
</div>
</div>
</div>
@endsection
@section('scripts')
{!! $html->scripts() !!}
@endsection
@extends('layouts.app')
@section('content')
<section id="main-content">
<section class="wrapper">
<section id="main-content">
<section class="wrapper">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Dashboard</h2>
</div>
<div class="panel-body">
Selamat datang di menu Sistem Informasi Pemesanan Makanan PizzaAndaliman. Silahkan pilih menu yang diinginkan.
</div>
</div>
</section>
</section>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Dashboard</h2>
</div>
<div class="panel-body">
Selamat datang di menu Sistem Informasi Pemesanan Makanan PizzaAndaliman. Silahkan pilih menu yang diinginkan.
</div>
</div>
</section>
</section>
@endsection
@section('scripts')
<script type="text/javascript">
<script type="text/javascript">
$(document).ready(function () {
var unique_id = $.gritter.add({
// (string | mandatory) the heading of the notification
title: "<span style='font-size: 12px;'>Welcome to PizzaAndaliman!",
// (string | mandatory) the text inside the notification
text: ' <a href="#" target="_blank" style="color:#ffd777">PizzaAndaliman@gmail.com / 081264721252</a>',
// (string | optional) the image to display on the left
image: 'css/theme/assets/img/pizza2.PNG',
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true,
// (int | optional) the time you want it to be alive for before fading out
time: '',
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
});
var unique_id = $.gritter.add({
// (string | mandatory) the heading of the notification
title: "<span style='font-size: 12px;'>Welcome to PizzaAndaliman!",
// (string | mandatory) the text inside the notification
text: ' <a href="#" target="_blank" style="color:#ffd777">PizzaAndaliman@gmail.com / 081264721252</a>',
// (string | optional) the image to display on the left
image: 'css/theme/assets/img/pizza2.PNG',
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true,
// (int | optional) the time you want it to be alive for before fading out
time: '',
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
});
return false;
return false;
});
</script>
@endsection
\ No newline at end of file
@extends('layouts.app')
@section('content')
<section id="main-content">
<section class="wrapper">
<section id="main-content">
<section class="wrapper">
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Dashboard</h2>
</div>
<div class="panel-body">
Selamat datang di menu Sistem Informasi Pemesanan Makanan PizzaAndaliman. Silahkan pilih menu yang diinginkan.
</div>
</div>
</section>
</section>
<div class="panel panel-default">
<div class="panel-heading">
<h2 class="panel-title">Dashboard</h2>
</div>
<div class="panel-body">
Selamat datang di menu Sistem Informasi Pemesanan Makanan PizzaAndaliman. Silahkan pilih menu yang diinginkan.
</div>
</div>
</section>
</section>
@endsection
@section('scripts')
<script type="text/javascript">
<script type="text/javascript">
$(document).ready(function () {
var unique_id = $.gritter.add({
// (string | mandatory) the heading of the notification
title: "<span style='font-size: 12px;'>Welcome to PizzaAndaliman!",
// (string | mandatory) the text inside the notification
text: ' <a href="#" target="_blank" style="color:#ffd777">PizzaAndaliman@gmail.com / 081264721252</a>',
// (string | optional) the image to display on the left
image: 'css/theme/assets/img/pizza2.PNG',
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true,
// (int | optional) the time you want it to be alive for before fading out
time: '',
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
});
var unique_id = $.gritter.add({
// (string | mandatory) the heading of the notification
title: "<span style='font-size: 12px;'>Welcome to PizzaAndaliman!",
// (string | mandatory) the text inside the notification
text: ' <a href="#" target="_blank" style="color:#ffd777">PizzaAndaliman@gmail.com / 081264721252</a>',
// (string | optional) the image to display on the left
image: 'css/theme/assets/img/pizza2.PNG',
// (bool | optional) if you want it to fade out on its own or just sit there
sticky: true,
// (int | optional) the time you want it to be alive for before fading out
time: '',
// (string | optional) the class name you want to apply to that specific message
class_name: 'my-sticky-class'
});
return false;
return false;
});
</script>
@endsection
\ No newline at end of file
......@@ -86,7 +86,8 @@
</a>
</li>
@endif
@role('admin')
@role('manager')
<li class="sub-menu">
<a href="javascript:;" >
......@@ -121,17 +122,18 @@
</ul>
</li>
@endrole
@role('manager')
@role('admin')
<li class="sub-menu">
<a href="javascript:;" >
<i class="fa fa-desktop"></i>
<span>Data Pelanggan</span>
<span>Data pesanan</span>
</a>
<ul class="sub">
<li><a href="{{ route('authors.index') }}">Pelanggan</a></li>
<li><a href="{{ route('authors.index') }}">Pesanan</a></li>
</ul>
</li>
......
......@@ -15,7 +15,7 @@ Auth::routes();
Route::get('/', 'HomeController@index');
Route::get('/Listbook', 'GuestController@index');
Route::get('/home', 'HomeController@index');
Route::group(['prefix'=>'admin', 'middleware'=>['auth', 'role:admin']], function () {
Route::group(['prefix'=>'admin', 'middleware'=>['auth']], function () {
Route::resource('authors', 'AuthorsController');
Route::resource('pegawai', 'PegawaiController');
......@@ -31,13 +31,13 @@ Route::group(['prefix'=>'admin', 'middleware'=>['auth', 'role:admin']], function
});
Route::get('books/{book}/borrow', [
'middleware' => ['auth', 'role:member'],
'middleware' => ['auth'],
'as' => 'guest.books.borrow',
'uses' => 'BooksController@borrow'
]);
Route::put('books/{book}/return', [
'middleware' => ['auth', 'role:member'],
'middleware' => ['auth'],
'as' => 'member.books.return',
'uses' => 'BooksController@returnBack'
]);
......
......@@ -11,10 +11,12 @@ return array(
'CreateAuthorsTable' => $baseDir . '/database/migrations/2016_12_12_114448_create_authors_table.php',
'CreateBooksTable' => $baseDir . '/database/migrations/2016_12_12_120408_create_books_table.php',
'CreateBorrowLogsTable' => $baseDir . '/database/migrations/2016_12_30_094623_create_borrow_logs_table.php',
'CreateDatapegawaiTable' => $baseDir . '/database/migrations/2017_05_08_085711_create_pegawai_table.php',
'CreatePasswordResetsTable' => $baseDir . '/database/migrations/2014_10_12_100000_create_password_resets_table.php',
'CreatePegawaisTable' => $baseDir . '/database/migrations/2017_05_23_014312_create_pegawais_table.php',
'CreatePesananTable' => $baseDir . '/database/migrations/2017_05_22_071700_create_pesanan_table.php',
'CreatePostsTable' => $baseDir . '/database/migrations/2016_12_11_110857_create_posts_table.php',
'CreateUsersTable' => $baseDir . '/database/migrations/2014_10_12_000000_create_users_table.php',
'CreatepegawaiTable' => $baseDir . '/database/migrations/2017_05_08_085711_create_pegawai_table.php',
'DatabaseSeeder' => $baseDir . '/database/seeds/DatabaseSeeder.php',
'File_Iterator' => $vendorDir . '/phpunit/php-file-iterator/src/Iterator.php',
'File_Iterator_Facade' => $vendorDir . '/phpunit/php-file-iterator/src/Facade.php',
......
......@@ -355,10 +355,12 @@ class ComposerStaticInit6daa598fae9ed14b9ff672201755e79c
'CreateAuthorsTable' => __DIR__ . '/../..' . '/database/migrations/2016_12_12_114448_create_authors_table.php',
'CreateBooksTable' => __DIR__ . '/../..' . '/database/migrations/2016_12_12_120408_create_books_table.php',
'CreateBorrowLogsTable' => __DIR__ . '/../..' . '/database/migrations/2016_12_30_094623_create_borrow_logs_table.php',
'CreateDatapegawaiTable' => __DIR__ . '/../..',
'CreatePasswordResetsTable' => __DIR__ . '/../..' . '/database/migrations/2014_10_12_100000_create_password_resets_table.php',
'CreatePegawaisTable' => __DIR__ . '/../..' . '/database/migrations/2017_05_23_014312_create_pegawais_table.php',
'CreatePesananTable' => __DIR__ . '/../..' . '/database/migrations/2017_05_22_071700_create_pesanan_table.php',
'CreatePostsTable' => __DIR__ . '/../..' . '/database/migrations/2016_12_11_110857_create_posts_table.php',
'CreateUsersTable' => __DIR__ . '/../..' . '/database/migrations/2014_10_12_000000_create_users_table.php',
'CreatepegawaiTable' => __DIR__ . '/../..' . '/database/migrations/2017_05_08_085711_create_pegawai_table.php',
'DatabaseSeeder' => __DIR__ . '/../..' . '/database/seeds/DatabaseSeeder.php',
'File_Iterator' => __DIR__ . '/..' . '/phpunit/php-file-iterator/src/Iterator.php',
'File_Iterator_Facade' => __DIR__ . '/..' . '/phpunit/php-file-iterator/src/Facade.php',
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment