Skip to content
Snippets Groups Projects
Commit 02401c6e authored by gazandi's avatar gazandi
Browse files

modul notifikasi schedule selesai

parent efc7e277
Branches
No related merge requests found
Pipeline #1650 skipped
...@@ -5,8 +5,11 @@ namespace App\Http\Controllers; ...@@ -5,8 +5,11 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\Schedule; use App\Schedule;
use App\Tps;
use App\User;
use Mail;
use App\Http\Requests; use App\Http\Requests;
use Illuminate\Support\Facades\Input;
class ScheduleController extends Controller class ScheduleController extends Controller
{ {
protected $user_roles = []; protected $user_roles = [];
...@@ -40,58 +43,111 @@ class ScheduleController extends Controller ...@@ -40,58 +43,111 @@ class ScheduleController extends Controller
public function index() public function index()
{ {
$arr = [];
if ($this->has_role('all_schedule')) if ($this->has_role('all_schedule'))
{ {
return view('menu.schedule',['data' => Schedule::all()]); $all = Schedule::all();
} }
else else
{ {
return view('menu.schedule', ['data' => Schedule::where('id_user', Auth::user()->id)->get()]); $all = Schedule::where('id_user', Auth::user()->id)->get();
}
foreach ($all as $jadwal) {
$tmp = [];
$tmp = $jadwal;
// dd($jadwal);
// $tmp->namauser = $jadwal->user()->get()['name'];
$tmp->namauser = User::find($jadwal->id_user)->name;
$tmp->namatps = Tps::find($jadwal->id_tps)->nama;
// $tmp->namatps = $jadwal->tps()->get()['nama'];
array_push($arr,$tmp);
} }
// dd($arr);
return view('menu.schedule', ['data' => $arr]);
} }
public function store() public function store()
{ {
$sched = Schedule::create(Input::all()); if ($this->has_role('all_schedule'))
return $sched; {
$sched = new Schedule;
$sched->id_tps = Input::get('id_tps',0);
$sched->id_user = Input::get('id_user',0);
$sched->time = Input::get('time','');
$sched->amount = Input::get('amount',1);
$sched->is_done = Input::get('is_done', 0);
$sched->id = 0;
$sched->save();
}
return redirect('/schedule');
} }
public function create() public function create()
{ {
// view create doang if ($this->has_role('all_schedule'))
{
return view('menu.insertSchedule', ['dataTPS' => Tps::all(['id', 'nama']),'dataManager' => User::all(['id', 'name'])]);
}else{
return redirect('/schedule');
}
} }
public function show($id) public function show($id)
{ {
// viewnya pake get // viewnya pake get
return Schedule::find($id); if ($this->has_role('all_schedule')||$this->has_role('edit_schedule'))
{
return Schedule::find($id);
}else{
return redirect('/schedule');
}
} }
public function edit($id) public function edit($id)
{ {
// viewnya pake form edit if ($this->has_role('all_schedule')||$this->has_role('edit_schedule'))
return Schedule::find($id); {
return view('menu.editSchedule',
['id' => $id,
'data' => Schedule::find($id),
'dataTPS' => Tps::all(['id', 'nama']),
'dataManager' => User::all(['id', 'name'])]);
}else{
return redirect('/schedule');
}
} }
public function update($id) public function update($id)
{ {
$sched = Schedule::find($id); $sched = Schedule::find($id);
$sched->update($input); if ($this->has_role('all_schedule'))
$tps = $sched->tps();
$tps->capacity_now += $sched->amount;
if ($tps->capacity_now >= $tps->capacity_full)
{ {
notify('TPS '.$tps->name.' penuh'); $sched = Schedule::find($id);
} $sched->id_tps = Input::get('id_tps');
$sched->id_user = Input::get('id_user');
$sched->time = Input::get('time','');
$sched->amount = Input::get('amount',1);
$sched->is_done = Input::get('is_done');
$sched->save();
$tps = Tps::find($sched->id_tps);
$tps->capacity_now += $sched->amount;
if ($tps->capacity_now >= $tps->capacity_full)
{
$this->notify('TPS '.$tps->nama.' penuh');
$tps->capacity_now = $tps->capacity_full;
$tps->is_full = 1;
}
$tps->save();
}
return redirect('/schedule'); return redirect('/schedule');
} }
public function destroy($id) public function destroy($id)
{ {
Schedule::find($id)->delete(); Schedule::find($id)->delete();
return Schedule::all(); return redirect('/schedule');
} }
public function notify($notif) public function notify($notif)
...@@ -99,10 +155,10 @@ class ScheduleController extends Controller ...@@ -99,10 +155,10 @@ class ScheduleController extends Controller
$data = [ $data = [
'content' => $notif, 'content' => $notif,
]; ];
$user = User::findOrFail(Input::get('id_user'));
Mail::send('emails.welcome', $data, function ($message) { Mail::send('email.notification', $data, function ($message) use ($user) {
$message->from(env('MAIL_USERNAME', 'user@host.suffix'), 'Notifikasi'); $message->from(env('MAIL_USERNAME', 'user@host.suffix'), 'Notifikasi');
$message->to($request->input('email'))->subject('Notifikasi Status TPS'); $message->to($user->email)->subject('Notifikasi Status TPS');
}); });
} }
} }
\ No newline at end of file
...@@ -6,7 +6,6 @@ use Illuminate\Http\Request; ...@@ -6,7 +6,6 @@ use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Auth;
use App\User; use App\User;
use App\Http\Requests; use App\Http\Requests;
use Illuminate\Support\Facades\Input; use Illuminate\Support\Facades\Input;
class UserController extends Controller class UserController extends Controller
{ {
......
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
</head> </head>
<body> <body>
<div> <div>
{{ content }} <?=$content?>
</div> </div>
</body> </body>
</html> </html>
\ No newline at end of file
...@@ -22,14 +22,14 @@ ...@@ -22,14 +22,14 @@
Form schedule Form schedule
</div> </div>
<div class="panel-body"> <div class="panel-body">
<form class="form-horizontal" method="POST" action="{{ url('/schedule') }}"> <form class="col-md-12" action="<?php echo URL::to('/schedule');?>/<?=$data->id?>" method="POST">
{!! csrf_field() !!} {!! csrf_field() !!}
<input type="hidden" name="_method" value="put" /> <input type="hidden" name="_method" value="put" />
<div class="line line-dashed b-b line-lg pull-in"></div> <div class="line line-dashed b-b line-lg pull-in"></div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">Nama Pengelola</label> <label class="col-sm-2 control-label">Nama Pengelola</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select name="idPengelola" ui-jq="chosen" class="w-full"> <select name="id_user" ui-jq="chosen" class="w-full">
<optgroup label="Nama Pengelola"> <optgroup label="Nama Pengelola">
@foreach ($dataManager as $Manager) @foreach ($dataManager as $Manager)
<option value=<?php echo $Manager->id;?> <option value=<?php echo $Manager->id;?>
...@@ -45,18 +45,25 @@ ...@@ -45,18 +45,25 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">Nama TPS</label> <label class="col-sm-2 control-label">Nama TPS</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select name="idPengelola" ui-jq="chosen" class="w-full"> <select name="id_tps" ui-jq="chosen" class="w-full">
<optgroup label="Nama Pengelola"> <optgroup label="Nama Pengelola">
@foreach ($dataTPS as $TPS) @foreach ($dataTPS as $TPS)
<option value=<?php echo $TPS->id;?> <option value=<?php echo $TPS->id;?>
<?php if($data->id_tps==$TPS->id) echo "selected";?> <?php if($data->id_tps==$TPS->id) echo "selected";?>
><?php echo $TPS->name;?></option> ><?php echo $TPS->nama;?></option>
@endforeach @endforeach
</optgroup> </optgroup>
</select> </select>
</div> </div>
</div> </div>
<div class="line line-dashed b-b line-lg pull-in"></div>
<div class="form-group">
<label class="col-sm-2 control-label">Amount</label>
<div class="col-sm-10">
<input type="text" placeholder="Amount" class="form-control" name="amount" required value="<?php echo $data->amount; ?>">
</div>
</div>
<div class="line line-dashed b-b line-lg pull-in"></div> <div class="line line-dashed b-b line-lg pull-in"></div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">Selesai</label> <label class="col-sm-2 control-label">Selesai</label>
...@@ -68,8 +75,9 @@ ...@@ -68,8 +75,9 @@
<i>Yes</i> <i>Yes</i>
</label> </label>
<label class="i-switch bg-warning m-t-xs m-r"> <label class="i-switch bg-warning m-t-xs m-r">
<input type="radio" name='is_full' value='0' > <input type="radio" name='is_done' value='0'
<?php if($data->is_done==0){echo "checked";}?> <?php if($data->is_done==0){echo "checked";}?>
>
<i>No</i> <i>No</i>
</label> </label>
</div> </div>
...@@ -92,7 +100,7 @@ ...@@ -92,7 +100,7 @@
<div class="form-group"> <div class="form-group">
<div class="col-sm-4 col-sm-offset-2"> <div class="col-sm-4 col-sm-offset-2">
<a href="{{ url('/schedule') }}"><button type="button" class="btn btn-default m-r-sm">Cancel</button></a> <a href="{{ url('/schedule') }}"><button type="button" class="btn btn-default m-r-sm">Cancel</button></a>
<button type="submit" class="btn btn-info">Create</button> <button type="submit" class="btn btn-info">Edit</button>
</div> </div>
</div> </div>
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">Nama Pengelola</label> <label class="col-sm-2 control-label">Nama Pengelola</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select name="idPengelola" ui-jq="chosen" class="w-full"> <select name="id_user" ui-jq="chosen" class="w-full">
<optgroup label="Nama Pengelola"> <optgroup label="Nama Pengelola">
@foreach ($dataManager as $Manager) @foreach ($dataManager as $Manager)
<option value=<?php echo $Manager->id;?>><?php echo $Manager->name;?></option> <option value=<?php echo $Manager->id;?>><?php echo $Manager->name;?></option>
...@@ -44,18 +44,22 @@ ...@@ -44,18 +44,22 @@
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">Nama TPS</label> <label class="col-sm-2 control-label">Nama TPS</label>
<div class="col-sm-10"> <div class="col-sm-10">
<select name="idPengelola" ui-jq="chosen" class="w-full"> <select name="id_tps" ui-jq="chosen" class="w-full">
<optgroup label="Nama Pengelola"> <optgroup label="Nama Pengelola">
@foreach ($dataTPS as $TPS) @foreach ($dataTPS as $TPS)
<option value=<?php echo $TPS->id;?>><?php echo $TPS->name;?></option> <option value=<?php echo $TPS->id;?>><?php echo $TPS->nama;?></option>
@endforeach @endforeach
</optgroup> </optgroup>
</select> </select>
</div> </div>
</div> </div>
<div class="line line-dashed b-b line-lg pull-in"></div>
<div class="form-group">
<label class="col-sm-2 control-label">Amount</label>
<div class="col-sm-10">
<input type="text" placeholder="Amount" class="form-control" name="amount" required >
</div>
</div>
<div class="line line-dashed b-b line-lg pull-in"></div> <div class="line line-dashed b-b line-lg pull-in"></div>
<div class="form-group"> <div class="form-group">
<label class="col-sm-2 control-label">Waktu Pengantaran</label> <label class="col-sm-2 control-label">Waktu Pengantaran</label>
......
...@@ -58,10 +58,11 @@ ...@@ -58,10 +58,11 @@
<i></i> <i></i>
</label> </label>
</th> </th>
<th>schedule</th> <th>Nama TPS</th>
<th>Supir Truk</th> <th>Nama Supir Truk</th>
<th>Amount</th>
<th>Waktu</th> <th>Waktu</th>
<th style="width:30px;"></th> <th>Selesai</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
...@@ -71,11 +72,15 @@ ...@@ -71,11 +72,15 @@
@foreach ($data as $jadwal) @foreach ($data as $jadwal)
<tr> <tr>
<td><label class="checkbox-inline "><input type="radio" name="id" value="<?=$jadwal->id?>"><i></i></label></td> <td><label class="checkbox-inline "><input type="radio" name="id" value="<?=$jadwal->id?>"><i></i></label></td>
<td><?php echo $jadwal->id_tps;?></td> <td><?php echo $jadwal->namatps;?></td>
<td><?php echo $jadwal->id_user;?></td> <td><?php echo $jadwal->namauser;?></td>
<td><?php echo $jadwal->amount;?></td>
<td><?php echo $jadwal->time;?></td> <td><?php echo $jadwal->time;?></td>
<td> <td>
<?php if($jadwal->is_done==1){?>
<a href class="active" ui-toggle-class><i class="fa fa-check text-success text-active"></i><i class="fa fa-times text-danger text"></i></a> <a href class="active" ui-toggle-class><i class="fa fa-check text-success text-active"></i><i class="fa fa-times text-danger text"></i></a>
<?php }else{?>
<a href ui-toggle-class><i class="fa fa-check text-success text-active"></i><i class="fa fa-times text-danger text"></i></a><?php }?>
</td> </td>
</tr> </tr>
@endforeach @endforeach
......
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