Commit 2c76d85b by hannan

save and redirect table to mandays page

parent 19fc6702
......@@ -7,7 +7,7 @@
<form class="ui form" action="{{route('timesheet::maintenance.savemandays')}}" method="POST">
{{csrf_field()}}
<table class="ui celled table">
<input type="hidden" name="pid" value="{{$pid}}">
<input type="hidden" name="id" value="{{$id}}">
<thead>
<tr>
<th style="width: 5%">No</th>
......@@ -19,21 +19,41 @@
<tbody>
<?php $limit = count($role); ?>
@foreach($role as $key => $value)
<tr>
<td>{{$key+1}}</td>
<!-- <td data-label="role">{{data_get($value,'role')}}</td> -->
<td data-label="role">{{data_get($value,'role.role')}}</td>
<?php
$d = $h = $tdays = $thours = 0;
foreach ($data as $key => $datas) {
if ( (data_get($datas,'fk_project') == $id) && (data_get($datas,'pm_roles') == data_get($value,'role.id')) ) {
$d = data_get($datas, 'pm_days');
$h = data_get($datas, 'pm_hours');
}
if (data_get($datas,'fk_project') == $id) {
$tdays += data_get($datas, 'pm_days');
$thours += data_get($datas, 'pm_hours');
}
}
?>
<td data-label="day">
<input type="text"
onkeypress="onlynumber(event)"
name="days[{{data_get($value,'role.id')}}]"
id="days[{{data_get($value,'role.id')}}]"
value="{{$d}}"
onchange="calcHours(this.value,{{$limit}},{{data_get($value,'role.id')}})">
</td>
<td data-label="hour">
<input type="text"
onkeypress="onlynumber(event)"
name="hours[{{data_get($value,'role.id')}}]"
id="hours[{{data_get($value,'role.id')}}]"
value="{{$h}}"
readonly="readonly">
</td>
</tr>
......@@ -42,10 +62,10 @@
<td></td>
<td>Total</td>
<td>
<input type="text" onkeypress="onlynumber(event)" name="totaldays" id="totaldays" readonly="readonly">
<input type="text" onkeypress="onlynumber(event)" name="totaldays" id="totaldays" value="{{$tdays}}" readonly="readonly">
</td>
<td>
<input type="text" onkeypress="onlynumber(event)" name="totalhours" id="totalhours" readonly="readonly">
<input type="text" onkeypress="onlynumber(event)" name="totalhours" id="totalhours" value="{{$thours}}" readonly="readonly">
</td>
</tr>
......
......@@ -14,6 +14,7 @@ use Portal\Timesheet\Model\Pteam;
use Portal\Timesheet\Model\Staff_info;
use Portal\Timesheet\Model\Overhead;
use Portal\Timesheet\Model\Role;
use Portal\Timesheet\Model\Pmandays;
use Portal\Timesheet\Model\VwMandays;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Input;
......@@ -135,7 +136,8 @@ class MaintenanceController extends Controller
->with('success', 'New Project Added');
}
public function updateProject(Request $request){
public function updateProject(Request $request)
{
$staffid = Users::find(Auth::id())
->u_staffID;
......@@ -153,7 +155,8 @@ class MaintenanceController extends Controller
return view('timesheet::maintenance.updateProject',compact('pm', 'project', 'staffid', 'pid'));
}
public function editproject(Request $request){
public function editproject(Request $request)
{
// dd($request);
$project = Project::where('id', $request->pid)->first();
......@@ -179,15 +182,10 @@ class MaintenanceController extends Controller
return redirect()->route('timesheet::maintenance.senaraiProject')->withSuccess('Project updated!');
}
public function mandays(Request $request){
$staffid = Users::find(Auth::id())
->u_staffID;
$project = Project::where('id', $request->id)
->first();
// dd($project);
// $role = Role::where('status', 1)
// ->get();
public function mandays(Request $request)
{
$data = Pmandays::where('fk_project', $request->id)->get();
// dd($data);
$role = VwMandays::where('fk_project_id', $request->id)
->with('role')
......@@ -195,15 +193,56 @@ class MaintenanceController extends Controller
// dd($role);
$pid = $request->id;
$id = $request->id;
// dd($pid);
return view('timesheet::maintenance.mandays',compact('project', 'staffid', 'pid', 'role'));
return view('timesheet::maintenance.mandays',compact('id', 'role', 'data'));
}
public function savemandays(Request $request)
{
dd($request);
// dump($request);
// dd(Pmandays::where('fk_project', $request->id)->get());
$staffid = Users::find(Auth::id())
->u_staffID;
$id = $request->id;
$check = Pmandays::where('fk_project', $request->id)->first();
// dd($check);
if ($check) {
//update
$data = Pmandays::where('fk_project', $request->id)->get();
foreach ($data as $key => $datas) {
foreach ($request->days as $key => $value) {
if ($datas->pm_roles == $key) {
$datas->pm_days = $value;
$datas->pm_hours = $value*8;
$datas->updated_by = $staffid;
$datas->save();
}
}
}
} else {
//add baru
foreach ($request->days as $key => $day) {
$data = new Pmandays;
$data->fk_project = $request->pid;
$data->pm_roles = $key;
$data->pm_days = $day;
$data->pm_hours = $day*8;
$data->updated_by = $staffid;
$data->save();
}
}
return redirect()->route('timesheet::maintenance.mandays', compact('id'));
}
public function senaraiProjectTeam(Request $request)
......
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