getTimestamp(); $nested_data = array(); $staff = Staff::with('StaffDetail')->where('company_id', $id)->where('roles_access','Installer')->orderBy('created_at','DESC')->withTrashed()->get(); if(!empty($staff)){ foreach($staff as $s){ $t_rating = 0; $count = count(Docket::where('installer_id',$s->_id)->get()); $docket = Docket::where('installer_id',$s->_id)->get(); if(!empty($docket)){ foreach($docket as $d){ $t_rating += $d->Rating1 + $d->Rating2 + $d->Rating3; } } if($t_rating > 0){ $t_rating = round(($t_rating/($count*15)) * 100); } $i++; array_push($nested_data, array( 'index' => $i, 'date' => date('d/m/Y H:i:a', strtotime($s->created_at)), 'installer_name' => $s->StaffDetail->name, 'total_docket' => $count, 'total_rating' => $t_rating.'%' )); } } return \DataTables::of($nested_data)->make(true); } /** * Get vendor contractor * * @return json */ public function getVendor($team) { $i=0; $curr = Carbon::now()->getTimestamp(); $nested_data = array(); $team = Company::where('team',$team)->orderBy('created_at','DESC')->get(); if(!empty($team)){ foreach ($team as $a) { $n1 = ''; $reg_time = Carbon::createFromFormat('Y-m-d H:i:s', $a->created_at); $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = 'New/'; } else{ $n1 = ''; } $i++; array_push($nested_data, array( 'index' => $n1.$i, 'name' => $a->name, 'address' => $a->address, 'city' => $a->city, 'state' => $a->state, 'postcode' => $a->postcode, 'action' => $a->_id )); } } return \DataTables::of($nested_data)->make(true); } /** * Get delete vendor contractor * * @return json */ public function requestDeleteVendor(Request $request) { $company = Company::where('_id',$request->id)->first(); if(!empty($company)){ $staff = Staff::with('StaffDetail')->where('company_id', $company->_id)->get(); if(!empty($staff)){ foreach ($staff as $key => $s) { $s->staffdetail()->delete(); $s->delete(); } } $company->delete(); return $this->sendResponse($company, 'Successfully delete vendor'); }else{ return $this->sendError('Vendor not found!', ''); } } /** * Get contractor list * * @return json */ public function getStaffList($roles,$company_id) { $i = 0; $curr = Carbon::now()->getTimestamp(); $nested_data = array(); if($company_id == 'null'){ $staff = Staff::with('Company','StaffDetail')->where('roles_access',$roles)->orderBy('created_at', 'desc')->get(); }else{ if($roles == 'Sales'){ $staff = Staff::with('Company','StaffDetail')->orderBy('created_at', 'desc')->where(function ($q) use($company_id){ $q->where('roles_access','Sales')->where('company_id',$company_id); })->orWhere(function ($q) use($company_id){ $q->where('roles_access','Dealer')->where('company_id',$company_id); })->get(); }else{ $staff = Staff::with('Company','StaffDetail')->where('roles_access',$roles)->where('company_id',$company_id)->orderBy('created_at', 'desc')->get(); } } foreach ($staff as $a) { $n1 = ''; $reg_time = $a->updated_at; $expiry_date = $reg_time->addDays(3); $expiry_date = $expiry_date->getTimestamp(); if($curr < $expiry_date) { $n1 = "New/"; } $i++; array_push($nested_data, array( 'index' => $n1.$i, 'user_pic' => $a->StaffDetail->user_pic, 'name' => $a->StaffDetail->name, 'ic' => $a->StaffDetail->ic, 'email' => $a->StaffDetail->email, 'phone' => $a->StaffDetail->phone, 'company_id' => $a->Company->name, 'position' => $a->StaffDetail->position, 'action' => $a->_id, 'action1' => $a->company_id, '_id' => $a->_id )); } return \DataTables::of($nested_data)->make(true); } /** * Delete contractor list * * @return json */ public function requestDeleteStaff(Request $request) { $staff = Staff::with('StaffDetail')->where('_id',$request->id)->first(); if(!empty($staff)){ if(!empty($staff->StaffDetail)){ $staff->staffdetail()->delete(); $staff->delete(); } return $this->sendResponse($staff, 'Successfully delete staff'); }else { return $this->sendError('Staff not found!', ''); } } }