whereHas('rab.mp_planning')->get(); return view('staff.curva-s-create',compact('projects')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if ($request->tanggal) { if(\Request::ajax()){ $cs = CurvaS::where([['id_project',$request->id_project],['tanggal',$request->tanggal]])->first(); if(!$cs){ $cs = CurvaS::create([ 'id_project' => $request->id_project, 'tanggal' => $request->tanggal, ]); } foreach ($request->id_rab_detail as $key => $value) { $cek = CurvasDet::where([['id_curva_s',$cs->id],['id_rab_detail',$value]])->first(); if($cek){ $cek->volume = str_replace(',','.',$request->volume[$key]); $cek->save(); }else{ CurvasDet::create([ 'id_curva_s' => $cs->id, 'id_rab_detail' => $value, 'volume' => str_replace(',','.',$request->volume[$key]), ]); } } return response()->json(['msg' => 'success']); }else{ foreach ($request->tanggal as $key => $value) { $cs = CurvaS::create([ 'id_project' => $request->id_project, 'tanggal' => $value, ]); if (isset($request->toArray()['id_rab_detail_'.$value])) { foreach ($request->toArray()['id_rab_detail_'.$value] as $key2 => $value2) { $volume = 0; if(isset($request->toArray()['volume_'.$value][$key2])){ $volume = str_replace(',','.',$request->toArray()['volume_'.$value][$key2]); } CurvasDet::create([ 'id_curva_s' => $cs->id, 'id_rab_detail' => $value2, 'volume' => $volume, ]); } } } return redirect()->route('curva_s.show',$request->id_project)->with('msg','Curva S berhasil dibuat'); } }else{ abort('404'); } } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request,$id) { if (\Request::ajax()) { if (isset($_GET['act'])) { if ($_GET['act'] == 'curvasdata') { $columns = array( 0 => 'id', ); $totalData = Project::count(); $totalFiltered = $totalData; $limit = $request->input('length'); $start = $request->input('start'); $order = $columns[$request->input('order.0.column')]; $dir = $request->input('order.0.dir'); if (empty($request->input('search.value'))) { if(Auth::user()->level == 'ARSITEK' || Auth::user()->level == 'DRAFTER' || Auth::user()->level == 'QUANTITY SURVEYOR') { $projects = Project::whereHas('rab.client', function($q){ $q->where('clients.id_user', Auth::user()->id); }) ->whereHas('curva_s') ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } else { $projects = Project::offset($start) ->whereHas('curva_s') ->limit($limit) ->orderBy($order, $dir) ->get(); } }else{ $search = $request->input('search.value'); if(Auth::user()->level == 'ARSITEK' || Auth::user()->level == 'DRAFTER' || Auth::user()->level == 'QUANTITY SURVEYOR') { $projects = Project::whereHas('rab.client', function($q) { $q->where('clients.id_user', Auth::user()->id); }) ->whereHas('curva_s') ->where('projects.name', 'LIKE', "%{$search}%") ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = Project::where('rab.client', function($q) { $q->where('clients.id_user', Auth::user()->id); }) ->whereHas('curva_s') ->where('projects.name', 'LIKE', "%{$search}%") ->count(); } else { $projects = Project::where('projects.name', 'LIKE', "%{$search}%") ->whereHas('curva_s') ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = Project::where('projects.name', 'LIKE', "%{$search}%") ->whereHas('curva_s') ->count(); } } $data = array(); if (!empty($projects)) { foreach ($projects as $row) { $nestedData['project'] = $row->name; if(RoleController::access('curva_s', 'edit') > 0 || RoleController::access('curva_s', 'create') > 0) { $nestedData['opsi'] = "
"; if($row->status_curva_s == 'non-approve') { $nestedData['opsi'] .= "
".csrf_field()." ".method_field('put')."
"; $nestedData['opsi'] .= " edit "; $nestedData['opsi'] .= "
" . csrf_field() . " " . method_field('delete') . "
"; } $nestedData['opsi'] .= " detail
"; } $data[] = $nestedData; } } $json_data = array( "draw" => intval($request->input('draw')), "recordsTotal" => intval($totalData), "recordsFiltered" => intval($totalFiltered), "data" => $data, ); echo json_encode($json_data); }elseif ($_GET['act'] == 'load_project') { $project = Project::with('curva_s')->findOrFail($id); $ahsS = AhsKategori::with(['subkategoris.ahsS' => function($q) use ($project){ $q->whereHas('rabDetail',function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); })->with(['rabDetail' => function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); }]); }])->with(['subkategoris.vendors' => function($q) use ($project){ $q->whereHas('rabDetail',function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); })->with(['rabDetail' => function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); }]); }])->orderBy('urutan','asc')->get(); $view = view('staff.curva-s-create_data',compact('project','ahsS'))->render(); return response()->json(['view' => $view,'project' => $project]); } } }else{ $project = Project::findOrFail($id); $ahsS = AhsKategori::with(['subkategoris.ahsS' => function($q) use ($project){ $q->whereHas('rabDetail',function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); })->with(['rabDetail' => function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); }]); }])->with(['subkategoris.vendors' => function($q) use ($project){ $q->whereHas('rabDetail',function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); })->with(['rabDetail' => function($q2) use ($project){ $q2->where('id_rab',$project->rab->id); }]); }])->orderBy('urutan','asc')->get(); return view('staff.curva-s-detail-new',compact('project','ahsS')); } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { $project = Project::findOrFail($id); return view('staff.curva-s-edit',compact('project')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { if ($request->act) { if ($request->act == 'item-update') { $cd = CurvasDet::where([['id_curva_s',$request->id_curva_s],['id_rab_detail',$request->id_rab_detail]])->first(); $cd->volume = str_replace(',', '.', $request->bobot_kerja); $cd->save(); return redirect()->route('curva_s.show',$cd->curva_s->project->id)->with('msg','Curva S Detail berhasil diubah'); }elseif ($request->act == 'approve-curva') { $p = Project::findOrFail($id); $p->status_curva_s = 'approve'; $p->save(); return redirect()->route('curva_s.index')->with('msg','Curva S berhasil disubmit'); } }else{ dd("... dalam perbaikan ..."); $project = Project::findOrFail($id); if ($project->curva_s) { foreach ($project->curva_s as $row) { if (isset($request->toArray()['id_rab_detail_'.$row->tanggal])) { foreach ($request->toArray()['id_rab_detail_'.$row->tanggal] as $key2 => $value2) { $volume = 0; if(isset($request->toArray()['volume_'.$row->tanggal][$key2])){ $volume = str_replace(',','.',$request->toArray()['volume_'.$row->tanggal][$key2]); } CurvasDet::where([ ['id_curva_s',$row->id], ['id_rab_detail',$value2], ])->update(['volume' => $volume]); } } } } if ($request->tanggal) { foreach ($request->tanggal as $key => $value) { $cs = CurvaS::create([ 'id_project' => $id, 'tanggal' => $value, ]); if (isset($request->toArray()['id_rab_detail_'.$value])) { foreach ($request->toArray()['id_rab_detail_'.$value] as $key2 => $value2) { $volume = 0; if(isset($request->toArray()['volume_'.$value][$key2])){ $volume = str_replace(',','.',$request->toArray()['volume_'.$value][$key2]); } CurvasDet::create([ 'id_curva_s' => $cs->id, 'id_rab_detail' => $value2, 'volume' => $volume, ]); } } } } return redirect()->route('curva_s.show',$id)->with('msg','Curva S berhasil diperbarui'); } } public static function getCurvasDet($id_curva_s,$id_rab_detail,$col = null) { $curva_s_det = CurvasDet::where([['id_curva_s',$id_curva_s],['id_rab_detail',$id_rab_detail]])->first(); if ($col == 'volume_progress') { return $curva_s_det?$curva_s_det->volume:0; }elseif($col == 'jasa'){ return $curva_s_det?$curva_s_det->volume / $curva_s_det->rab_detail->volume * 100:0; }elseif ($col == 'progress') { $material = TimeLineController::getProgressDetail(null,$id_rab_detail,'material_percent'); $progress_material = TimeLineController::getProgressDetail(null,$id_rab_detail,'progress_material_percent'); $jasa = CurvasController::getCurvasDet($id_curva_s,$id_rab_detail,'jasa'); $progress_jasa = (100-$progress_material); return ($material * $progress_material) + ($jasa * $progress_jasa) / 100; }elseif ($col == 'bobot_kerja') { $bobot = $curva_s_det?$curva_s_det->rab_detail->subtotal / $curva_s_det->curva_s->project->rab->harga_deal * 100:0; return $bobot * CurvasController::getCurvasDet($id_curva_s,$id_rab_detail,'jasa') / 100 ; }elseif ($col == 'status') { return $curva_s_det?$curva_s_det->status:0; } } public static function getTotalBobot($id_curva_s){ $total = CurvasDet::selectRaw('sum(volume) as total') ->where('id_curva_s',$id_curva_s)->first()->total; return $total; } public static function getCrossCheck($id_curva_s,$id_rab_detail){ $total = CurvasDet::selectRaw('sum(volume) as total') ->where([['id_curva_s',$id_curva_s],['id_rab_detail',$id_rab_detail]])->first()->total; return $total; } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { CurvaS::where('id_project',$id)->delete(); return redirect()->route('curva_s.index')->with('msg','data berhasil dihapus'); } }