/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // Check authorisation and throw 404 if not if (!Auth::user()->allowedTo('add', 'issue.report')) { return view('errors/404'); } $site_id = ''; if (Session::has('siteID')) { $site_id = Site::where('code', Session::get('siteID'))->first()->id; } return view('site/site-issue/create', compact(['site_id'])); }
/** * Show the application dashboard. * * @return Response */ public function index(Request $request) { //alert()->info("It's alive!","Welcome")->persistent('Close'); $worksite = ''; if (Session::has('siteID')) { $worksite = Site::where('code', Session::get('siteID'))->first(); if (!$worksite->isUserOnsite(Auth::user()->id)) { if ($worksite->id == 25) { return view('site/checkinStore', compact('worksite')); } return view('site/checkin', compact('worksite')); } } if (Auth::user()->password_reset) { return redirect('/user/' . Auth::user()->username . '/settings/password'); } return view('pages/home', compact('worksite')); }
/** * A list of sites this company is on a Planner for * * @return \Illuminate\Database\Eloquent\Collection */ public function sitePlannerList($status = '') { $client_list = $this->reportsToCompany()->clients->pluck('id')->toArray(); if ($status != '') { $collection = Site::where('status', $status)->whereIn('client_id', $client_list)->get(); } else { $collection = Site::whereIn('client_id', $client_list)->get(); } // If Company has no Parent then return full collection // ie. a list of all sites of all their own clients if (!$this->parentCompany) { return $collection; } $logged_site_id = ''; if (Session::has('siteID')) { $site_code = Session::get('siteID'); $site = Site::where(['code' => $site_code])->first(); $logged_site_id = $site->id; } // Otherwise return a filtered collection of sites that company is on Planner for $filteredCollection = []; foreach ($collection as $site) { $onPlanner = SitePlanner::where('site_id', $site->id)->where('entity_type', 'c')->where('entity_id', $this->id)->first(); if (!$onPlanner && $site->id != $logged_site_id) { $filteredCollection[] = $site->id; } } return $collection->except($filteredCollection); }
/** * A dropdown list of sites this supervisor has authority over * * @return array */ public function supervisorSiteListSelect($status = '', $prompt = '') { $array = []; $client_list = $this->company->clients->pluck('id')->toArray(); if ($status) { $collection = Site::where('status', $status)->whereIn('client_id', $client_list)->get(); } else { $collection = Site::whereIn('client_id', $client_list)->get(); } foreach ($collection as $site) { $record = Site::findOrFail($site->id); if ($this->is('supervisor') && $record->isUserSupervisor($this)) { $array[$site->id] = $record->name; } else { if ($this->is('full.access|full.read.access|whs.admin|general.admin|construction.manager')) { $array[$site->id] = $record->name; } } } asort($array); if ($prompt == 'all') { return $prompt && count($array) > 1 ? $array = array('' => 'All Sites') + $array : $array; } return $prompt && count($array) > 1 ? $array = array('' => 'Select Site') + $array : $array; }
/** * Process Site Check-in. * * @return \Illuminate\Http\Response */ public function processCheckin(SiteCheckinRequest $request, $slug) { $site = Site::where(compact('slug'))->firstOrFail(); if ($request->has('safe_site')) { $site->attendance()->save(new SiteAttendance(['safe_site' => '1'])); } else { $site->attendance()->save(new SiteAttendance(['safe_site' => '0'])); // Create Issue + attach to site if ($request->has('action_required')) { $issue = $site->issues()->save(new SiteIssue($request->only('reason', 'action_required'))); } else { $issue = $site->issues()->save(new SiteIssue($request->only('reason'))); } //Create action taken + attach to issue if ($issue) { $action_request = $request->only('action'); $action = $issue->actions()->save(new SiteIssueAction($action_request)); // Handle attached Photo or Video if ($request->hasFile('media')) { $issue->saveAttachedMedia($request->file('media')); } // Email issue $issue->emailIssue($action); } } // if Today add them to Roster if Company is on Planer but user not on Roster $today = Carbon::now()->format('Y-m-d'); if ($site->isCompanyOnPlanner(Auth::user()->company->id, $today) && !$site->isUserOnRoster(Auth::user()->id, $today)) { $newRoster = SiteRoster::create(array('site_id' => $site->id, 'user_id' => Auth::user()->id, 'date' => $today . ' 00:00:00', 'created_by' => '1', 'updated_by' => '1')); } Toastr::success("Checked in"); return redirect('/dashboard'); }
/** * Display a listing of plans. * * @return \Illuminate\Http\Response */ public function listPlans() { if (!Auth::user()->can('view.site.doc|view.p.site.doc')) { return view('errors/404'); } $site_id = ''; if (Session::has('siteID')) { $site_code = Session::get('siteID'); $site = Site::where(['code' => $site_code])->first(); $site_id = $site->id; } return view('site/doc/plan/list', compact('site_id')); }
/** * Migrate Reports */ public function reports() { echo "<h1>Migrating Report Categorys</h1>"; DB::table('safety_docs_categories')->truncate(); DB::table('site_docs_categories')->truncate(); $genCat = SafetyDocCategory::create(array('type' => 'SDS', 'name' => 'General', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); $genCat = SiteDocCategory::create(array('type' => 'RISK', 'name' => 'General', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); set_time_limit(60); $cats = zReportsCats::all(); $cats->each(function ($cat) { echo "<b>" . $cat->type . "</b> - {$cat->name}<br>"; $status = '0'; if ($cat->active == "y") { $status = '1'; } $type = $cat->type; if ($type == 'MSDS') { $type = 'SDS'; } if ($type == 'CWMS') { $type = 'WMS'; } if ($type == 'AAAA') { $type = 'AAA'; } if ($type == 'PLAN') { /*$newCat = SiteDocCategory::create(array( 'type' => $type, 'name' => reformatOldStr($cat->name), 'parent' => $cat->parent, 'status' => $status, 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1', ));*/ } else { if ($type == 'SDS') { $newCat = SiteDocCategory::create(array('type' => 'RISK', 'name' => reformatOldStr($cat->name), 'parent' => $cat->parent, 'status' => $status, 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); } if ($cat->id != 41) { $newCat = SafetyDocCategory::create(array('type' => $type, 'name' => reformatOldStr($cat->name), 'parent' => $cat->parent, 'status' => $status, 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); } } }); $hazCat = SafetyDocCategory::create(array('type' => 'HAZ', 'name' => 'Hazardous Materiels', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1')); /*$wmsCat = SafetyDocCategory::create(array( 'type' => 'WMS', 'name' => 'Work Method Statement', 'parent' => '0', 'status' => '1', 'company_id' => '3', 'created_by' => '1', 'updated_by' => '1', ));*/ echo "<h1>Completed</h1>"; echo "<h1>Migrating Reports</h1>"; DB::table('site_docs')->truncate(); DB::table('safety_docs')->truncate(); DB::table('wms_docs')->truncate(); $reports = zReports::all(); $reports->each(function ($report) { echo "<b>" . $report->type . "</b> - {$report->reportfile}<br>"; $status = '0'; if ($report->active == "y") { $status = '1'; } $site_id = null; $site = Site::where('code', $report->jobnum)->first(); if ($site) { $site_id = $site->id; } $hazCat = SafetyDocCategory::where('type', 'HAZ')->first(); //$wmsCat = SafetyDocCategory::where('type', 'WMS')->first(); $type = $report->type; $cat = $report->cat; $cid = null; $newdir = 'filebank/'; if ($report->reportfile) { list($dir, $filename) = explode('/', $report->reportfile); switch ($dir) { case 'msds': $type = 'SDS'; $filename = substr($filename, 1); $newdir .= 'whs/sds/'; break; case 'hazard': $type = 'HAZ'; $cat = $hazCat->id; $newdir .= 'site/' . $site->id . '/hazard/'; break; case 'risk': $newdir .= 'site/' . $site->id . '/risk/'; break; case 'plans': /*$cid = $cat; $lookup = DB::table('z_lookup_company')->where('old', $cid)->get(); if ($lookup) $company = Company::find($lookup[0]->new); else $lookup = ['0' => (object) array('new' => '1')]; $cid = $lookup[0]->new;*/ $cat = '0'; $newdir .= 'site/' . $site->id . '/plan/'; break; case 'toolbox': $newdir .= 'whs/toolbox/'; break; case 'workmethod': $cid = $cat; $lookup = DB::table('z_lookup_company')->where('old', $cid)->get(); if ($lookup) { $company = Company::find($lookup[0]->new); } else { $lookup = ['0' => (object) array('new' => '1')]; } $cid = $lookup[0]->new; $newdir .= 'company/' . $cid . '/wms/'; break; } if ($report->updated_by == 'Guest') { $report->updated_by = 'latham'; } $user = User::where('username', $report->updated_by)->first(); if ($type == 'CWMS') { $newWMS = WmsDoc::create(array('name' => reformatOldStr($report->title), 'reportfile' => $filename, 'version' => '1.0', 'status' => '2', 'builder' => '0', 'master' => '0', 'principle' => 'Cape Cod', 'principle_id' => '3', 'principle_signed_id' => $user->id, 'principle_signed_date' => $report->updated, 'for_company_id' => $cid, 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated)); } else { if ($type == 'PLAN' || $type == 'RISK' || $type == 'HAZ') { // readjust category id's to new tables (asuming they added in table order if ($cat == '35') { $cat = 1; } elseif ($cat == '36') { $cat = 1; } elseif ($cat == '37') { $cat = 1; } elseif ($cat == '38') { $cat = 1; } elseif ($cat == '39') { $cat = 1; } elseif ($cat == '40') { $cat = 1; } elseif ($cat == '41') { $cat = 1; } elseif ($cat == '42') { $cat = 36; } elseif ($cat == '43') { $cat = 37; } else { $cat++; } $newReport = SiteDoc::create(array('type' => $type, 'category_id' => $cat, 'site_id' => $site_id, 'reportfile' => $filename, 'name' => reformatOldStr($report->title), 'status' => $status, 'for_company_id' => null, 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated)); } else { // readjust category id's to new tables (asuing they added in table order if ($cat == '41') { $cat = 1; } elseif ($cat == '42') { $cat = 36; } elseif ($cat == '43') { $cat = 37; } else { $cat++; } $newReport = SafetyDoc::create(array('type' => $type, 'category_id' => $cat, 'site_id' => $site_id, 'reportfile' => $filename, 'name' => reformatOldStr($report->title), 'status' => $status, 'for_company_id' => $cid, 'company_id' => '3', 'created_by' => $user->id, 'updated_by' => $user->id, 'created_at' => $report->updated, 'updated_at' => $report->updated)); } } // Copy file to new location if (file_exists('filebankOrig/' . $report->reportfile)) { $newfile = $newdir . $filename; if (!file_exists($newdir)) { mkdir($newdir, 0777, true); echo "created directory {$newdir} <br>"; } if (!file_exists($newfile)) { echo "copying to {$newfile}<br>"; if (!copy('filebankOrig/' . $report->reportfile, $newfile)) { echo "*** FAILED to copy {$report->reportfile}...\n"; } } } } }); echo "<h1>Completed</h1>"; }
/** * Show the application login form. * * OVERRIDES the default from Illuminate\Foundation\Auth\AuthenticatesUsers * * @return \Illuminate\Http\Response */ public function getLogin() { if (view()->exists('auth.authenticate')) { return view('auth.authenticate'); } $worksite = ''; if (Session::has('siteID')) { $site_id = Session::get('siteID'); $worksite = Site::where(['code' => $site_id])->first(); if (!$worksite) { Session::forget('siteID'); } } return view('auth.login', compact('worksite')); }