Commit 1baa4d3d by Azhan Hannan

Project man-days - simpan total day n hours dalam table project as p_total_days, p_total_hours

parent 2bd9741e
...@@ -193,11 +193,12 @@ class MaintenanceController extends Controller ...@@ -193,11 +193,12 @@ class MaintenanceController extends Controller
// dd($data); // dd($data);
$role = VwMandays::where('fk_project_id', $request->id) $role = VwMandays::where('fk_project_id', $request->id)
->where('role_id','<>','7')
->with('role') ->with('role')
->orderBy('role_id') ->orderBy('role_id')
->get(); ->get();
// dd($role); // dd($role);s
$id = $request->id; $id = $request->id;
// dd($pid); // dd($pid);
...@@ -215,25 +216,42 @@ class MaintenanceController extends Controller ...@@ -215,25 +216,42 @@ class MaintenanceController extends Controller
$id = $request->id; $id = $request->id;
$check = Pmandays::where('fk_project', $request->id)->first(); $check = Pmandays::where('fk_project', $request->id)->first();
// $check = Pmandays::where('fk_project', $request->id)->get();
// dd($check); // dd($check);
if ($check) { if ($check)
//update {
foreach ($request->days as $key => $value)
$data = Pmandays::where('fk_project', $request->id)->get(); {
foreach ($data as $key => $datas) { $datas = Pmandays::where('fk_project', $id)
foreach ($request->days as $key => $value) { ->where('pm_roles', $key)
if ($datas->pm_roles == $key) { ->first();
$datas->pm_days = $value; if ($datas)
$datas->pm_hours = $value*8; {
$datas->updated_by = $staffid; $datas->pm_days = $value;
$datas->save(); $datas->pm_hours = $value*8;
} $datas->updated_by = $staffid;
$datas->save();
}
else
{
$data = new Pmandays;
$data->fk_project = $request->id;
$data->pm_roles = $key;
$data->pm_days = $value;
$data->pm_hours = $value*8;
$data->updated_by = $staffid;
$data->save();
} }
} }
Project::where('id', $request->id)
->update([
'p_total_hours' => $request->totalhours,
'p_total_days' => $request->totaldays,
]);
} else { } else {
//add baru
foreach ($request->days as $key => $day) { foreach ($request->days as $key => $day) {
$data = new Pmandays; $data = new Pmandays;
...@@ -243,8 +261,13 @@ class MaintenanceController extends Controller ...@@ -243,8 +261,13 @@ class MaintenanceController extends Controller
$data->pm_hours = $day*8; $data->pm_hours = $day*8;
$data->updated_by = $staffid; $data->updated_by = $staffid;
$data->save(); $data->save();
} }
Project::where('id', $request->id)
->update([
'p_total_hours' => $request->totalhours,
'p_total_days' => $request->totaldays,
]);
} }
return redirect()->route('timesheet::maintenance.mandays', compact('id')); return redirect()->route('timesheet::maintenance.mandays', compact('id'));
......
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