get(); return view('staff.progress',compact('rabs')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { $rabs = Rab::whereHas('project')->get(); return view('staff.progress-create-new',compact('rabs')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $progress = Progress::selectRaw('id,(week(curdate()) - week(progress.tanggal)) as WeeksOut') ->orderBy('tanggal','desc')->where('id_rab',$request->id)->first(); $newWeek = ''; if ($progress) { if ($progress->WeeksOut > 0) { $newWeek = $progress->id; $progress = Progress::create([ 'id_rab' => $request->id, 'tanggal' => date('Y-m-d'), ]); } }else{ $progress = Progress::create([ 'id_rab' => $request->id, 'tanggal' => date('Y-m-d'), ]); } foreach ($request->rab_detail as $key => $value) { if ($newWeek) { $volume = ProgressDetail::selectRaw('sum(volume) as volume') ->where([ ['id_progress',$newWeek], ['id_rab_detail',$value] ])->first()->volume; $volume += (int)str_replace(',', '.', $request->volume[$key]); }else{ $volume = (int)str_replace(',', '.', $request->volume[$key]); } ProgressDetail::create([ 'id_progress' => $progress->id, 'id_rab_detail' => $value, 'material_percent' => isset($request->toArray()['material_percent_'.$value])?$request->toArray()['material_percent_'.$value][0]:null, 'progress_material_percent' => isset($request->toArray()['progress_material_percent_'.$value])?$request->toArray()['progress_material_percent_'.$value][0]:null, 'progress_jasa_percent' => isset($request->toArray()['progress_jasa_percent_'.$value])?$request->toArray()['progress_jasa_percent_'.$value][0]:null, 'volume' => $volume, 'tanggal' => date('Y-m-d'), 'id_user' => Auth::user()->id, ]); } return redirect()->route('timeline.index')->with('msg','progress berhasil dibuat'); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show(Request $request,$id) { if (\Request::ajax()) { if ($request->act) { if ($request->act == 'loadPekerjaan') { $ahsS = AhsKategori::with(['subkategoris.ahsS' => function($q) use ($id){ $q->whereHas('rabDetail',function($q2) use ($id){ $q2->where('id_rab',$id); })->with(['rabDetail' => function($q2) use ($id){ $q2->where('id_rab',$id); }]); }])->with(['subkategoris.vendors' => function($q) use ($id){ $q->whereHas('rabDetail',function($q2) use ($id){ $q2->where('id_rab',$id); })->with(['rabDetail' => function($q2) use ($id){ $q2->where('id_rab',$id); }]); }])->orderBy('urutan','asc')->get(); $rab = Rab::findOrFail($id); return view('staff.progress-create-new-pekerjaan_data',compact('ahsS','rab')); } } } } public static function materialPercent($id_rab,$id_ahs,$id_rab_detail = null) { $last_progress = Progress::orderBy('id','desc')->where('id_rab',$id_rab)->first(); if ($last_progress) { $progress = ProgressDetail::orderBy('id','desc')->where([ ['id_progress',$last_progress->id], ['id_rab_detail',$id_rab_detail] ])->first(); if ($progress) { return $progress->material_percent; } }else{ $row = RabDetail::where([ ['id_rab',$id_rab], ['id_ahs',$id_ahs] ])->first(); $total_anggaran = 0; $total_terambil = 0; foreach($row->ahs->ahsMaterialDetails as $row2): $terambil = CmaterialController::getQtyterambil($row->id_rab,$row->id_ahs,$row2->material->id) == null?0:CmaterialController::getQtyterambil($row->id_rab,$row->id_ahs,$row2->material->id); $total_anggaran += $row2->material->harga * ($row2->koefisien * $row->volume); $total_terambil += $terambil * ($row2->material->harga); endforeach; return $total_terambil > 0?($total_terambil / $total_anggaran * 100):0; } } public static function progressMaterialPercent($id_rab,$id_ahs,$id_rab_detail = null) { $last_progress = Progress::orderBy('id','desc')->where('id_rab',$id_rab)->first(); if ($last_progress) { $progress = ProgressDetail::orderBy('id','desc')->where([ ['id_progress',$last_progress->id], ['id_rab_detail',$id_rab_detail] ])->first(); if ($progress) { return $progress->progress_material_percent; } }else{ $row = RabDetail::where([ ['id_rab',$id_rab], ['id_ahs',$id_ahs] ])->first(); $total_anggaran = 0; foreach($row->ahs->ahsMaterialDetails as $row2): $terambil = CmaterialController::getQtyterambil($row->id_rab,$row->id_ahs,$row2->material->id) == null?0:CmaterialController::getQtyterambil($row->id_rab,$row->id_ahs,$row2->material->id); $total_anggaran += $row2->material->harga * ($row2->koefisien * $row->volume); endforeach; return $total_anggaran > 0?$total_anggaran / $row->subtotal * 100:0; } } public static function getJasaPercent($id_rab,$id_ahs,$id_rab_detail = null) { $last_progress = Progress::orderBy('id','desc')->where('id_rab',$id_rab)->first(); if ($last_progress) { $progress = ProgressDetail::orderBy('id','desc')->where([ ['id_progress',$last_progress->id], ['id_rab_detail',$id_rab_detail] ])->first(); if ($progress) { return TimeLineController::getProgressDetail($last_progress->id,$id_rab_detail,'volume_progress') / $progress->rabDetail->volume * 100; } }else{ return 0; } } public static function getProgressPercent($id_rab,$id_ahs,$id_rab_detail = null) { $last_progress = Progress::orderBy('id','desc')->where('id_rab',$id_rab)->first(); if ($last_progress) { $progress = ProgressDetail::orderBy('id','desc')->where([ ['id_progress',$last_progress->id], ['id_rab_detail',$id_rab_detail] ])->first(); if ($progress) { return TimeLineController::getProgressDetail($last_progress->id,$id_rab_detail,'progress_percent'); } }else{ return 0; } } public static function getbobotkerja($id_rab,$id_ahs,$id_rab_detail = null) { $last_progress = Progress::orderBy('id','desc')->where('id_rab',$id_rab)->first(); if ($last_progress) { $progress = ProgressDetail::orderBy('id','desc')->where([ ['id_progress',$last_progress->id], ['id_rab_detail',$id_rab_detail] ])->first(); if ($progress) { return TimeLineController::getProgressDetail($last_progress->id,$id_rab_detail,'bobot_kerja'); } }else{ return 0; } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }