get(); $user = User::whereHas('labourOrder')->get(); return view('staff.labour-order', compact('project', 'user')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function bulantoRomawi($num) { if ($num <= 12) { $ro = $arrayName = array( 1 => 'I', 2 => 'II', 3 => 'III', 4 => 'IV', 5 => 'V', 6 => 'VI', 7 => 'VII', 8 => 'VIII', 9 => 'IX', 10 => 'X', 11 => 'XI', 12 => 'XII'); return $ro[(int) $num]; } else { dd('jumlah bulan hanya ada 12'); } } public function create() { if (!Auth::user()->curr_siteproject) { return redirect()->back()->with('error', 'silahkan isi site project anda terlebih dahulu'); } $no_lo = LabourOrder::orderBy('no_lo', 'DESC') ->where('id_site_project', Auth::user()->curr_siteproject)->first(); if (!$no_lo) { $no_lo = 'BD-001/LO-' . Auth::user()->siteProject->code . '/' . $this->bulantoRomawi(date('m')) . '/' . date('Y'); } else { $no_lo = explode('/', $no_lo->no_lo)[0]; $no_lo = (int) substr($no_lo, -3) + 1; $no_lo = 'BD-' . sprintf('%03s', $no_lo) . '/LO-' . Auth::user()->siteProject->code . '/' . $this->bulantoRomawi(date('m')) . '/' . date('Y'); } $no_lo = strtoupper($no_lo); $mandors = Mandor::all(); $projects = Project::whereHas('rab', function ($q) { $q->where('status', 'approve'); })->get(); return view('staff.labour-order-create',compact('mandors','projects','no_lo')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { if (!Auth::user()->curr_siteproject) { return redirect()->back()->with('error', 'silahkan isi site project anda terlebih dahulu'); } $no_lo = LabourOrder::orderBy('no_lo', 'DESC') ->where('id_site_project', Auth::user()->curr_siteproject)->first(); if (!$no_lo) { $no_lo = 'BD-001/LO-' . Auth::user()->siteProject->code . '/' . $this->bulantoRomawi(date('m')) . '/' . date('Y'); } else { $no_lo = explode('/', $no_lo->no_lo)[0]; $no_lo = (int) substr($no_lo, -3) + 1; $no_lo = 'BD-' . sprintf('%03s', $no_lo) . '/LO-' . Auth::user()->siteProject->code . '/' . $this->bulantoRomawi(date('m')) . '/' . date('Y'); } $no_lo = strtoupper($no_lo); $lo = LabourOrder::create([ 'no_lo' => $no_lo, 'id_mandor' => $request->mandor, 'id_project' => $request->project, 'id_site_project' => Auth::user()->curr_siteproject, 'tanggal' => date('Y-m-d'), 'status' => 'draft', 'id_user' => Auth::user()->id ]); if ($request->choose == 'harian') { LabourOrderHarian::create([ 'id_labour_order' => $lo->id, 'from_date' => $request->from_date, 'to_date' => $request->to_date, 'total_upah' => str_replace('.','',$request->upah_terbayar), ]); }elseif ($request->choose == 'borongan') { LabourOrderBorongan::create([ 'id_labour_order' => $lo->id, 'total_upah' => str_replace('.','',$request->upah_terbayar), ]); } return redirect()->route('labour_order.index')->with('msg','data berhasil dibuat'); } /** * 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'] == 'labourOrderData') { $columns = array( 0 => 'id', 1 => 'id', 2 => 'tanggal', ); $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') { if($_GET['project'] != '' || $_GET['status'] != '' || $_GET['user'] != '' || $_GET['time'] != '' || $_GET['interval_1'] != '') { $totalData = LabourOrder::where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-'. $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } return $query->where($filter); }) ->count(); } else { $totalData = LabourOrder::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($_GET['project'] != '' || $_GET['status'] != '' || $_GET['user'] != '' || $_GET['time'] != '' || $_GET['interval_1'] != '') { $labour_orders = LabourOrder::where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-' . $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } return $query->where($filter); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } else { $labour_orders = LabourOrder::offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } } else { $search = $request->input('search.value'); if($_GET['project'] != '' || $_GET['status'] != '' || $_GET['user'] != '' || $_GET['time'] != '' || $_GET['interval_1'] != '') { $labour_orders = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-' . $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } return $query->where($filter); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-' . $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } return $query->where($filter); }) ->count(); } else { $labour_orders = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->count(); } } } else { if($_GET['project'] != '' || $_GET['status'] != '' || $_GET['user'] != '' || $_GET['time'] != '' || $_GET['interval_1'] != '') { $totalData = LabourOrder::where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-'. $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } $filter[] = ['id_user', Auth::user()->id]; return $query->where($filter); }) ->count(); } else { $totalData = LabourOrder::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'))) { if($_GET['project'] != '' || $_GET['status'] != '' || $_GET['user'] != '' || $_GET['time'] != '' || $_GET['interval_1'] != '') { $labour_orders = LabourOrder::where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-' . $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } $filter[] = ['id_user', Auth::user()->id]; return $query->where($filter); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } else { $labour_orders = LabourOrder::where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); } } else { $search = $request->input('search.value'); if($_GET['project'] != '' || $_GET['status'] != '' || $_GET['user'] != '' || $_GET['time'] != '' || $_GET['interval_1'] != '') { $labour_orders = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-' . $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } $filter[] = ['id_user', Auth::user()->id]; return $query->where($filter); }) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->where(function($query) { $filter = []; if($_GET['project'] != '') { $filter[] = ['id_project', $_GET['project']]; } if($_GET['status'] != '') { $filter[] = ['status', $_GET['status']]; } if($_GET['user'] != '') { $filter[] = ['id_user', $_GET['user']]; } if($_GET['time'] != '') { if($_GET['time'] == 'this-month') { $bulan = date('m'); $tahun = date('Y'); $jml_hari = date('t', mktime(0, 0, 0, $bulan+1, 0, $tahun)); $filter[] = ['tanggal', '>=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-01'))]; $filter[] = ['tanggal', '<=', date('Y-m-d', strtotime($tahun . '-' . $bulan . '-' . $jml_hari))]; } elseif ($_GET['time'] == 'last-week') { $previous_week = strtotime("-1 week +1 day"); $start_week = strtotime("last sunday midnight",$previous_week); $end_week = strtotime("next saturday",$start_week); $start_week = date("Y-m-d",$start_week); $end_week = date("Y-m-d",$end_week); $filter[] = ['tanggal', '>=', $start_week]; $filter[] = ['tanggal', '<=', $end_week]; } elseif($_GET['time'] == 'last-month') { $first_day = date("Y-m-d", strtotime("first day of previous month")); $last_day = date("Y-m-d", strtotime("last day of previous month")); $filter[] = ['tanggal', '>=', $first_day]; $filter[] = ['tanggal', '<=', $last_day]; } elseif($_GET['time'] == 'interval') { $first_date = date('Y-m-d', strtotime($_GET['interval_1'])); $end_date = date('Y-m-d', strtotime($_GET['interval_2'])); $filter[] = ['tanggal', '>=', $first_date]; $filter[] = ['tanggal', '<=', $end_date]; } } $filter[] = ['id_user', Auth::user()->id]; return $query->where($filter); }) ->count(); } else { $labour_orders = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->where('id_user', Auth::user()->id) ->offset($start) ->limit($limit) ->orderBy($order, $dir) ->get(); $totalFiltered = LabourOrder::whereHas('project',function($q) use ($search){ $q->where('projects.name','LIKE', "%{$search}%"); })->orWhereHas('mandor',function($q) use ($search){ $q->where('mandors.name','LIKE', "%{$search}%"); }) ->where('id_user', Auth::user()->id) ->count(); } } } $data = array(); if (!empty($labour_orders) && $labour_orders->count() > 0) { foreach ($labour_orders as $row) { $nestedData['project'] = $row->project->name; $nestedData['no_lo'] = $row->no_lo; $nestedData['status'] = $row->status; $nestedData['nominal'] = 'Rp ' . number_format($row->labourOrderBorongan?$row->labourOrderBorongan->total_upah:$row->labourOrderHarian->total_upah,0,',','.'); $nestedData['tanggal'] = $row->tanggal; $nestedData['mandor'] = $row->mandor->name; if($row->id_user == NULL) { $nestedData['created_by'] = ''; } else { $nestedData['created_by'] = $row->user->fullname; } $nestedData['opsi'] = "
"; if(RoleController::access('lo', 'edit') > 0 && $row->status == 'draft'){ $nestedData['opsi'] .= "
".csrf_field()." ".method_field('put')."
"; } if(RoleController::access('lo', 'view') > 0) { $nestedData['opsi'] .= " detail "; } if (RoleController::access('lo', 'delete') > 0) { $nestedData['opsi'] .= "
" . csrf_field() . " " . method_field('delete') . "
"; } $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'] == 'getAbsensi') { $tanggal = DailyReport::select('created_at') ->whereBetween('created_at',array($request->from_date,$request->to_date)) ->where('id_project', $id)->get(); $pekerja = DatabasePekerja::where('id_project', $id)->get(); $view = view('staff.labour-order-create_absensi-data',compact('tanggal','pekerja'))->render(); return response()->json(['view' => $view]); }elseif ($_GET['act'] == 'getProgress') { $project = Project::with('progress','progress.progress_details','progress.progress_details.rab_detail','progress.progress_details.rab_detail.ahs','progress.progress_details.rab_detail.ahs_vendor')->findOrFail($id); $bobot_kerja = 0; foreach($project->progress as $row2){ foreach($row2->progress_details as $row3){ if($row3->rab_detail->ahs){ $bobot_kerja += round(TimeLineController::getProgressDetail($row2->id,$row3->rab_detail->id,'bobot_kerja'),2); }else{ $progress = round((TimeLineController::getProgressDetail($row2->id,$row3->rab_detail->id,'volume_progress') / $row3->rab_detail->volume * 100),2); $bobot = round($row3->rab_detail->subtotal / $project->rab->harga_deal * 100,2) / 100; $bobot_kerja += $bobot * $progress; } } } $progressS = $project->progress->toArray(); if (count($progressS) > 1) { $progress_minggu_kemarin_d = $progressS[count($progressS) - 2]; $progress_minggu_kemarin = 0; foreach($progress_minggu_kemarin_d['progress_details'] as $row3){ if($row3['rab_detail']['ahs']){ $progress_minggu_kemarin += round(TimeLineController::getProgressDetail($progress_minggu_kemarin_d['id'],$row3['rab_detail']['id'],'bobot_kerja'),2); }else{ $progress = round((TimeLineController::getProgressDetail($progress_minggu_kemarin_d['id'],$row3['rab_detail']['id'],'volume_progress') / $row3['rab_detail']['volume'] * 100),2); $bobot = round($row3['rab_detail']['subtotal'] / $project->rab->harga_deal * 100,2) / 100; $progress_minggu_kemarin += $bobot * $progress; } } }else{ $progress_minggu_kemarin = 0; } if (count($progressS) > 0) { $progress_minggu_ini_d = $progressS[count($progressS)-1]; $progress_minggu_ini = 0; foreach($progress_minggu_ini_d['progress_details'] as $row3){ if($row3['rab_detail']['ahs']){ $progress_minggu_ini += round(TimeLineController::getProgressDetail($progress_minggu_ini_d['id'],$row3['rab_detail']['id'],'bobot_kerja'),2); }else{ $progress = round((TimeLineController::getProgressDetail($progress_minggu_ini_d['id'],$row3['rab_detail']['id'],'volume_progress') / $row3['rab_detail']['volume'] * 100),2); $bobot = round($row3['rab_detail']['subtotal'] / $project->rab->harga_deal * 100,2) / 100; $progress_minggu_ini += $bobot * $progress; } } }else{ $progress_minggu_ini = 0; } $total = 0; foreach($project->rab->rabDetailsMandor as $row): $total += $row->subtotal; endforeach; return response()->json([ 'total_progress' => round($bobot_kerja,2), 'progress_minggu_kemarin' => round($progress_minggu_kemarin,2), 'progress_minggu_ini' => round($progress_minggu_ini,2), 'total_upah_rab_mandor' => number_format($total,0,"",".") , 'upah_minggu_ini' => number_format($progress_minggu_ini * $total / 100,0,"",".") ]); } } }else{ $lo = LabourOrder::findOrFail($id); return view('staff.labour-order-detail',compact('lo')); } } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit(Request $request,$id) { if ($request->act == 'bill') { $banks = Bank::all(); $lo = LabourOrder::findOrFail($id); return view('staff.labour-order-convert_bill',compact('lo','banks')); }elseif($request->act == 'payment'){ $banks = Bank::all(); $lo = LabourOrder::findOrFail($id); return view('staff.labour-order-record_payment',compact('lo','banks')); }else{ abort('404'); } } /** * 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 == 'approve-labour_order') { $lo = LabourOrder::findOrFail($id); $lo->status = 'open'; $lo->save(); return redirect()->route('labour_order.index')->with('msg', 'data berhasil disubmit'); }elseif ($request->act == 'edit-item') { $loD = LabourOrderDetail::findOrFail($id); $loD->qty = str_replace(",", ".", $request->qty); $loD->total_upah = str_replace(".", "", $request->total_upah); $loD->save(); if ($loD->belongsToManyPekerjaan()) { $loD->belongsToManyPekerjaan()->sync($request->pekerjaan); } if ($request->redirect) { return redirect($request->redirect) ->with('last_id',$request->last_id) ->with('last_bill',$request->bill) ->with('last_date',$request->date) ->with('last_duedate',$request->due_date) ->with('msg', 'data berhasil dirubah'); }else{ return redirect()->route('labour_order.edit', $loD->id_labour_order) ->with('last_bill',$request->bill) ->with('last_date',$request->date) ->with('last_duedate',$request->due_date) ->with('msg', 'data berhasil dirubah'); } } } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { LabourOrder::destroy($id); return redirect()->route('labour_order.index')->with('msg', 'data berhasil dihapus'); } }