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
// dd($data);
$role = VwMandays::where('fk_project_id', $request->id)
->where('role_id','<>','7')
->with('role')
->orderBy('role_id')
->get();
// dd($role);
// dd($role);s
$id = $request->id;
// dd($pid);
......@@ -215,25 +216,42 @@ class MaintenanceController extends Controller
$id = $request->id;
$check = Pmandays::where('fk_project', $request->id)->first();
// $check = Pmandays::where('fk_project', $request->id)->get();
// 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();
}
if ($check)
{
foreach ($request->days as $key => $value)
{
$datas = Pmandays::where('fk_project', $id)
->where('pm_roles', $key)
->first();
if ($datas)
{
$datas->pm_days = $value;
$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 {
//add baru
foreach ($request->days as $key => $day) {
$data = new Pmandays;
......@@ -243,8 +261,13 @@ class MaintenanceController extends Controller
$data->pm_hours = $day*8;
$data->updated_by = $staffid;
$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'));
......
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