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.timeline-create-pekerjaan_data',compact('ahsS','rab')); }elseif ($request->act == 'progressdata') { set_time_limit(0); $columns = array( 0 => 'id', ); $level = Auth::user()->level; if (strtoupper($level) == 'SUPERADMIN' || strtoupper($level) == 'GENERAL MANAGER' || strtoupper($level) == 'FINANCE MANAGER' || strtoupper($level) == 'SUPPLY CHAIN MANAGER' || strtoupper($level) == 'MARKETING MANAGER' || strtoupper($level) == 'PROJECT MANAGER') { $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'))) { $projects = Project::offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); }else{ $search = $request->input('search.value'); $projects = Project::where('projects.name', 'LIKE', "%{$search}%") ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = Project::where('projects.name', 'LIKE', "%{$search}%") ->count(); } } else { $totalData = Project::where('id_user', Auth::user()->id)->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'))) { $projects = Project::where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); }else{ $search = $request->input('search.value'); $projects = Project::where([['projects.name', 'LIKE', "%{$search}%"],['projects.id_user', Auth::user()->id]]) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = Project::where([['projects.name', 'LIKE', "%{$search}%"],['projects.id_user', Auth::user()->id]]) ->count(); } } $data = array(); if (!empty($projects)) { foreach ($projects as $row) { $nestedData['project'] = $row->name; $nestedData['client'] = $row->owner->fullname; $bobot_kerja = 0; foreach($row->progress as $row2){ foreach($row2->progress_details as $row3){ if($row3->rab_detail->ahs){ $bobot_kerja += round($this->getProgressDetail($row2->id,$row3->rab_detail->id,'bobot_kerja'),2); }else{ $progress = round(($this->getProgressDetail($row2->id,$row3->rab_detail->id,'volume_progress') / $row3->rab_detail->volume * 100),2); $bobot = round($row3->rab_detail->subtotal / $row->rab->harga_deal * 100,2) / 100; $bobot_kerja += $bobot * $progress; } } } $nestedData['progress'] = $bobot_kerja.'%'; if($row->id_user == NULL) { $nestedData['created_by'] = ''; } else { $nestedData['created_by'] = $row->user->fullname; } $nestedData['opsi'] = "
"; $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); } } }else{ $project = Project::findOrFail($request->id); $ahsS = AhsKategori::with(['subkategoris.ahsS' => function($q) use ($project){ $q->whereHas('rabDetail',function($q2) use ($project){ $q2->where('id_rab',$project->rab?$project->rab->id:null); })->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?$project->rab->id:null); })->with(['rabDetail' => function($q2) use ($project){ $q2->where('id_rab',$project->rab?$project->rab->id:null); }]); }])->orderBy('urutan','asc')->get(); return view('staff.timeline-detail-new',compact('ahsS','project')); } } public static function getProgressDetail($id_progress,$id_rab_detail,$col = null,$minggu_ke = null) { if ($minggu_ke) { $progress_det = ProgressDetail::whereHas('progress',function($q) use ($minggu_ke){ $q->where('minggu_ke',$minggu_ke); })->where('id_rab_detail',$id_rab_detail)->first(); }else{ $progress_det = ProgressDetail::where([['id_progress',$id_progress],['id_rab_detail',$id_rab_detail]])->first(); } if ($col == 'volume_progress') { return $progress_det?$progress_det->volume:0; }elseif($col == 'jasa'){ return $progress_det?$progress_det->volume / $progress_det->rab_detail->volume * 100:0; }elseif ($col == 'progress') { $material = TimeLineController::getProgressDetail($id_progress,$id_rab_detail,'material_percent',$minggu_ke); $progress_material = TimeLineController::getProgressDetail(null,$id_rab_detail,'progress_material_percent',$minggu_ke); $jasa = TimeLineController::getProgressDetail($id_progress,$id_rab_detail,'jasa',$minggu_ke); $progress_jasa = (100-$progress_material); return ($material * $progress_material/100) + ($jasa * $progress_jasa /100); }elseif ($col == 'bobot_kerja') { if($progress_det){ $bobot = $progress_det->rab_detail->subtotal / $progress_det->progress->project->rab->harga_deal * 100; return $bobot * TimeLineController::getProgressDetail($id_progress,$id_rab_detail,'progress',$minggu_ke) / 100 ; }else{ return 0; } }elseif ($col == 'material_percent') { $row = RabDetail::where('id',$id_rab_detail)->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; if ($row->material_percent == 0) { return $total_terambil > 0?($total_terambil / $total_anggaran * 100):0; }else{ return $row->material_percent; } }elseif ($col == 'progress_material_percent') { $row = RabDetail::where('id',$id_rab_detail)->first(); $total_material = 0; foreach($row->ahs->ahsMaterialDetails as $row2): $total_material += $row2->koefisien * $row2->material->harga; endforeach; $harga_modal = AhsController::cekTotalAhs($row->ahs->id); return $total_material > 0?$total_material / $harga_modal * 100:0; }elseif ($col == 'status') { if ($progress_det) { return $progress_det->status; }else{ return '-'; } } } public static function cekminggu($id_project,$minggu_ke) { $cek = Progress::where([['id_project',$id_project],['minggu_ke',$minggu_ke]])->first(); return $cek; } /** * 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) { if ($request->act) { if ($request->act == 'item-update') { $pd = ProgressDetail::where([['id_progress',$request->id_progress],['id_rab_detail',$request->id_rab_detail]])->first(); $pd->volume = str_replace(',', '.', $request->volume_progress); $pd->save(); return redirect()->route('timeline.show',$id)->with('msg','Volume Progress berhasil diubah'); }elseif ($request->act == 'approve-item') { $pd = ProgressDetail::where([['id_progress',$request->id_progress],['id_rab_detail',$request->id_rab_detail]])->first(); $pd->status = 'approve'; $pd->save(); return response()->json(['msg' => 'success']); }elseif ($request->act == 'material_percent-update') { $rbd = RabDetail::findOrFail($request->id_rab_detail); $rbd->material_percent = str_replace(',', '.', $request->material_percent); $rbd->save(); return redirect()->route('timeline.show',$id)->with('msg','Material Percent berhasil diperbarui'); } }else{ if ($request->tanggal) { foreach ($request->tanggal as $key => $value) { $p = Progress::create([ 'id_project' => $id, 'tanggal' => $value, 'minggu_ke' => $request->minggu_ke[$key], ]); if (isset($request->toArray()['id_rab_detail_'.$value])) { foreach ($request->toArray()['id_rab_detail_'.$value] as $key2 => $value2) { ProgressDetail::create([ 'id_progress' => $p->id, 'id_rab_detail' => $value2, 'volume' => str_replace(',','.',$request->toArray()['volume_'.$value][$key2]), ]); } } } return redirect()->route('timeline.show',$id)->with('msg','Progress berhasil dibuat'); } } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }