From f4e2923f3afa7973a028aa68db168f1d96d79af6 Mon Sep 17 00:00:00 2001 From: icalF <laser.survivor@gmail.com> Date: Mon, 4 Apr 2016 20:40:00 +0700 Subject: [PATCH] mail notif and update schedule table --- app/Http/Controllers/ScheduleController.php | 24 +++++++++++++-- app/Http/Controllers/TpsController.php | 30 +++++++++++-------- app/Http/Controllers/UserController.php | 7 +++-- app/Http/routes.php | 1 + app/UsersRoles.php | 18 +++++++++++ ...16_04_04_055311_create_schedules_table.php | 1 + resources/views/email/notification.blade.php | 13 ++++++++ 7 files changed, 78 insertions(+), 16 deletions(-) create mode 100644 app/UsersRoles.php create mode 100644 resources/views/email/notification.blade.php diff --git a/app/Http/Controllers/ScheduleController.php b/app/Http/Controllers/ScheduleController.php index 33d62cd..d400d5f 100644 --- a/app/Http/Controllers/ScheduleController.php +++ b/app/Http/Controllers/ScheduleController.php @@ -46,7 +46,7 @@ class ScheduleController extends Controller } else { - return view('menu.schedule',['data' => Schedule::where('id_user', Auth::user()->id)->get()]); + return view('menu.schedule', ['data' => Schedule::where('id_user', Auth::user()->id)->get()]); } } @@ -77,7 +77,15 @@ class ScheduleController extends Controller { $sched = Schedule::find($id); $sched->update($input); - return $sched; + + $tps = $sched->tps(); + $tps->capacity_now += $sched->amount; + if ($tps->capacity_now >= $tps->capacity_full) + { + notify('TPS '.$tps->name.' penuh'); + } + + return redirect('/schedule'); } public function destroy($id) @@ -85,4 +93,16 @@ class ScheduleController extends Controller Schedule::find($id)->delete(); return Schedule::all(); } + + public function notify($notif) + { + $data = [ + 'content' => $notif, + ]; + + Mail::send('emails.welcome', $data, function ($message) { + $message->from(env('MAIL_USERNAME', 'user@host.suffix'), 'Notifikasi'); + $message->to($request->input('email'))->subject('Notifikasi Status TPS'); + }); + } } \ No newline at end of file diff --git a/app/Http/Controllers/TpsController.php b/app/Http/Controllers/TpsController.php index b0eff5f..223aed7 100644 --- a/app/Http/Controllers/TpsController.php +++ b/app/Http/Controllers/TpsController.php @@ -53,17 +53,17 @@ class TpsController extends Controller $tmp->managerName = $tps->manager()->get(['name'])[0]->name; array_push($arr,$tmp); } - return view('menu.tps',['data' => $arr]); + return view('menu.tps', ['data' => $arr]); } public function store() { $tps = new Tps; - $tps->capacity_now = Input::get('capacity_now',0); - $tps->capacity_full = Input::get('capacity_full',0); + $tps->capacity_now = Input::get('capacity_now', 0); + $tps->capacity_full = Input::get('capacity_full', 0); $tps->nama = Input::get('name',''); - $tps->is_full = Input::get('is_full',0); - $tps->id_manager = Input::get('idPengelola',0); + $tps->is_full = Input::get('is_full', 0); + $tps->id_manager = Input::get('idPengelola', 0); $tps->id = 0; $tps->save(); //$tps = Tps::create(Input::all()); @@ -73,7 +73,9 @@ class TpsController extends Controller public function create() { // view create doang - return view('menu.insertTps',['dataManager' => User::all(['id','name'])]); + return view('menu.insertTps', [ + 'dataManager' => User::all(['id', 'name']) + ]); } public function show($id) @@ -85,17 +87,21 @@ class TpsController extends Controller public function edit($id) { // viewnya pake form edit - return view('menu.editTps',['id'=>$id,'data' => Tps::find($id),'dataManager' => User::all(['id','name'])]); + return view('menu.editTps', [ + 'id' => $id, + 'data' => Tps::find($id), + 'dataManager' => User::all(['id', 'name']) + ]); } public function update($id) { $tps = Tps::find($id); - $tps->capacity_now = Input::get('capacity_now',0); - $tps->capacity_full = Input::get('capacity_full',0); - $tps->nama = Input::get('name',''); - $tps->is_full = Input::get('is_full',0); - $tps->id_manager = Input::get('idPengelola',0); + $tps->capacity_now = Input::get('capacity_now', 0); + $tps->capacity_full = Input::get('capacity_full', 0); + $tps->nama = Input::get('name', ''); + $tps->is_full = Input::get('is_full', 0); + $tps->id_manager = Input::get('idPengelola', 0); $tps->save(); return redirect('/tps'); } diff --git a/app/Http/Controllers/UserController.php b/app/Http/Controllers/UserController.php index 5b0ecdc..14d6cf6 100644 --- a/app/Http/Controllers/UserController.php +++ b/app/Http/Controllers/UserController.php @@ -43,7 +43,7 @@ class UserController extends Controller public function index() { - return view('menu.user',['data' => User::all()]); + return view('menu.user', ['data' => User::all()]); } public function store() @@ -70,7 +70,10 @@ class UserController extends Controller public function edit($id) { // viewnya pake form edit - return view('menu.editUser',['id'=>$id,'data' => User::find($id)]); + return view('menu.editUser', [ + 'id' => $id, + 'data' => User::find($id) + ]); } public function update($id) diff --git a/app/Http/routes.php b/app/Http/routes.php index 558ea36..a09cb51 100644 --- a/app/Http/routes.php +++ b/app/Http/routes.php @@ -13,6 +13,7 @@ Route::group(['middleware' => 'web'], function () { Route::auth(); + Route::get('/', 'HomeController@index'); // homnya kan cm 1 Route::get('/home', 'HomeController@index'); diff --git a/app/UsersRoles.php b/app/UsersRoles.php new file mode 100644 index 0000000..10077fe --- /dev/null +++ b/app/UsersRoles.php @@ -0,0 +1,18 @@ +<?php + +namespace App; + +use Illuminate\Database\Eloquent\Model; + +class UsersRoles extends Model +{ + public function user() + { + return $this->hasOne('App\User', 'id', 'id_user'); + } + + public function role() + { + return $this->hasOne('App\User', 'id', 'id_role'); + } +} diff --git a/database/migrations/2016_04_04_055311_create_schedules_table.php b/database/migrations/2016_04_04_055311_create_schedules_table.php index eccf548..280d4f7 100644 --- a/database/migrations/2016_04_04_055311_create_schedules_table.php +++ b/database/migrations/2016_04_04_055311_create_schedules_table.php @@ -17,6 +17,7 @@ class CreateSchedulesTable extends Migration $table->increments('id'); $table->integer('id_tps')->unsigned(); $table->integer('id_user')->unsigned(); + $table->integer('amount')->unsigned(); $table->boolean('is_done'); $table->timestamp('time'); $table->timestamps(); diff --git a/resources/views/email/notification.blade.php b/resources/views/email/notification.blade.php new file mode 100644 index 0000000..ffecbcc --- /dev/null +++ b/resources/views/email/notification.blade.php @@ -0,0 +1,13 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <meta http-equiv="X-UA-Compatible" content="IE=edge"> + <link rel="stylesheet" href=""> +</head> +<body> + <div> + {{ content }} + </div> +</body> +</html> \ No newline at end of file -- GitLab