예제 #1
0
 /**
  * Email Action Notification
  */
 public function emailAction($action)
 {
     $issue = SiteIssue::findOrFail($action->issue_id);
     $site = Site::findOrFail($issue->site_id);
     $email_list = env('EMAIL_ME');
     if (\App::environment('prod')) {
         $email_list = "*****@*****.**";
     } else {
         if (\App::environment('dev')) {
             //$email_list = "jo@capecod.com.au; tara@capecod.com.au; " . $email_list;
         }
     }
     $email_list = explode(';', $email_list);
     $email_list = array_map('trim', $email_list);
     // trim white spaces
     $email_user = \App::environment('prod', 'dev') ? Auth::user()->email : '';
     $data = ['id' => $issue->id, 'site' => $site->name . ' (' . $site->code . ')', 'date' => Carbon::now()->format('d/m/Y g:i a'), 'user_fullname' => Auth::user()->fullname, 'user_company_name' => Auth::user()->company->name, 'action' => $action->action, 'site_owner' => $site->client->clientOfCompany->name];
     $filename = $this->photo;
     Mail::send('emails/siteIssueAction', $data, function ($m) use($email_list, $email_user, $site, $filename, $action) {
         $m->from('*****@*****.**');
         $m->to($email_list);
         if (preg_match(VALID_EMAIL_PATTERN, $email_user)) {
             $m->cc($email_user);
         }
         $m->subject('WHS Issue Update Notification');
     });
 }
예제 #2
0
 /**
  * Email Issue
  */
 public function emailIssue($action)
 {
     $site = Site::findOrFail($this->site_id);
     $email_list = env('EMAIL_ME');
     if (\App::environment('prod')) {
         $email_list = "gary@capecod.com.au; jo@capecod.com.au; tara@capecod.com.au; " . $email_list;
         foreach ($site->supervisors as $super) {
             if (preg_match(VALID_EMAIL_PATTERN, $super->email)) {
                 $email_list .= '; ' . $super->email;
             }
         }
     } else {
         if (\App::environment('dev')) {
             //$email_list = "jo@capecod.com.au; tara@capecod.com.au; ".$email_list;
         }
     }
     $email_list = explode(';', $email_list);
     $email_list = array_map('trim', $email_list);
     // trim white spaces
     $email_user = \App::environment('prod', 'dev') ? Auth::user()->email : '';
     $data = ['id' => $this->id, 'site' => $site->name . ' (' . $site->code . ')', 'address' => $site->address . ', ' . $site->SuburbStatePostcode, 'date' => Carbon::now()->format('d/m/Y g:i a'), 'user_fullname' => Auth::user()->fullname, 'user_company_name' => Auth::user()->company->name, 'reason' => $this->reason, 'action' => $action->action, 'site_owner' => $site->client->clientOfCompany->name];
     $filename = $this->photo;
     Mail::send('emails/siteIssue', $data, function ($m) use($email_list, $email_user, $site, $filename, $action) {
         $m->from('*****@*****.**');
         $m->to($email_list);
         if (preg_match(VALID_EMAIL_PATTERN, $email_user)) {
             $m->cc($email_user);
         }
         $m->subject('WHS Issue Notification');
         $file_path = public_path('filebank/site/' . $site->id . '/issue/' . $filename);
         if ($filename && file_exists($file_path)) {
             $m->attach($file_path);
         }
     });
 }
예제 #3
0
 /**
  * Email Accident
  */
 public function emailAccident()
 {
     $site = Site::findOrFail($this->site_id);
     $email_list = env('EMAIL_ME');
     if (\App::environment('dev', 'prod')) {
         $email_list = "robert@capecod.com.au; gary@capecod.com.au; tara@capecod.com.au; jo@capecod.com.au; " . $email_list;
         foreach ($site->supervisors as $super) {
             if (preg_match(VALID_EMAIL_PATTERN, $super->email)) {
                 $email_list .= '; ' . $super->email;
             }
         }
     }
     $email_list = trim($email_list);
     $email_list = explode(';', $email_list);
     $email_list = array_map('trim', $email_list);
     // trim white spaces
     $email_user = \App::environment('dev', 'prod') ? Auth::user()->email : '';
     $data = ['id' => $this->id, 'site' => $site->name . ' (' . $site->code . ')', 'address' => $site->address . ', ' . $site->SuburbStatePostcode, 'date' => $this->date->format('d/m/Y g:i a'), 'worker' => $this->name . ' (age: ' . $this->age . ')', 'occupation' => $this->occupation, 'location' => $this->location, 'nature' => $this->nature, 'referred' => $this->referred, 'damage' => $this->damage, 'description' => $this->info, 'user_fullname' => User::find($this->created_by)->fullname, 'user_company_name' => User::find($this->created_by)->company->name, 'submit_date' => $this->created_at->format('d/m/Y g:i a'), 'site_owner' => $site->client->clientOfCompany->name];
     Mail::send('emails.siteAccident', $data, function ($m) use($email_list, $email_user) {
         $m->from('*****@*****.**');
         $m->to($email_list);
         if (preg_match(VALID_EMAIL_PATTERN, $email_user)) {
             $m->cc($email_user);
         }
         $m->subject('WHS Accident Notification');
     });
 }
예제 #4
0
 public function plannerSite($site_id, $date, $weeks)
 {
     $site = Site::findOrFail($site_id);
     //return view('pdf.plan-site', compact('site'));
     $pdf = PDF::loadView('pdf.plan-site', compact('site', 'date', 'weeks'))->setOrientation('landscape')->setOption('margin-bottom', 0);
     //$file = public_path('filebank/company/' . $doc->for_company_id . '/wms/' . $doc->name . ' v' . $doc->version . ' ref-' . $doc->id . ' ' . '.pdf');
     //if (file_exists($file))
     //    unlink($file);
     //$pdf->save($file);
     return $pdf->stream();
     //return $pdf->download('invoice.pdf');
     //PDF::loadHTML($html)->setPaper('a4')->setOrientation('landscape')->setOption('margin-bottom', 0)->save('myfile.pdf')
 }
예제 #5
0
 /**
  * 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'));
 }
예제 #6
0
 /**
  * Store a newly created resource in storage.
  *
  * @return \Illuminate\Http\Response
  */
 public function store(SiteAccidentRequest $request)
 {
     // Check authorisation and throw 404 if not
     if (!Auth::user()->allowedTo('add', 'accident.report')) {
         return view('errors/404');
     }
     $accident_request = $request->all();
     // Format date from datetime picker to mysql format
     $date = new Carbon(preg_replace('/-/', '', $request->get('date')));
     $accident_request['date'] = $date->format('Y-m-d H:i:s');
     // Create Site Accident
     $accident = SiteAccident::create($accident_request);
     // Email accident
     $accident->emailAccident();
     Toastr::success("Lodged accident report");
     $worksite = Site::find($accident_request['site_id']);
     return view('pages/home', compact('worksite'));
 }
예제 #7
0
 public static function dailyUpdate()
 {
     $log = '';
     //echo "<h1>Adding New Entities to Roster</h1>";
     $log .= "Adding New Entities to Roster\n\n";
     $capecod = '3';
     $company = Company::findOrFail($capecod);
     $allowedSites = $company->siteList('1')->pluck('id')->toArray();
     $allowedSites = Site::all()->pluck('id')->toArray();
     $date = Carbon::now()->format('Y-m-d');
     //$date = '2016-08-17';
     $planner = SitePlanner::select(['id', 'site_id', 'entity_type', 'entity_id', 'task_id', 'from', 'to', 'days'])->where('from', '<=', $date)->where('to', '>=', $date)->whereIn('site_id', $allowedSites)->orderBy('site_id')->get();
     foreach ($planner as $plan) {
         if ($plan->entity_type == 'c') {
             $site = Site::find($plan->site_id);
             $company = Company::findOrFail($plan->entity_id);
             $staff = $company->staffActive()->pluck('id')->toArray();
             $log .= "\nf:" . $plan->from->format('Y-m-d') . ' t:' . $plan->to->format('Y-m-d') . ' [' . $plan->id . '] (' . $company->name . ") Task:{$plan->task_id} Site: {$site->name} ({$plan->site_id})\n";
             foreach ($staff as $staff_id) {
                 $user = User::findOrFail($staff_id);
                 if (!$site->isUserOnRoster($staff_id, $date)) {
                     //echo 'adding '.$user->fullname.' ('.$user->username.') to roster<br>';
                     $log .= 'adding ' . $user->fullname . ' (' . $user->username . ") to roster\n";
                     $newRoster = SiteRoster::create(array('site_id' => $site->id, 'user_id' => $staff_id, 'date' => $date . ' 00:00:00', 'created_by' => '1', 'updated_by' => '1'));
                 }
             }
         }
     }
     //echo "<h1>Completed</h1>";
     $log .= "\nCompleted";
     $now = Carbon::now()->format('Y-m-d-G-i-s');
     $bytes_written = File::put(public_path('filebank/log/nightly/' . $now . '.txt'), $log);
     if ($bytes_written === false) {
         die("Error writing to file");
     } else {
         echo 'Logfile filebank/log/nightly/' . $now . '.txt';
     }
     echo $log;
 }
예제 #8
0
파일: User.php 프로젝트: unclefudge/whs
 /**
  * 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;
 }
예제 #9
0
 /**
  * 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');
 }
예제 #10
0
 /**
  * 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>";
 }
예제 #11
0
 /**
  * Get List of Site Without Supervisor options for 'select' dropdown in Vuejs format
  */
 public function getSitesWithoutSuper(Request $request)
 {
     $allowedSites = Auth::user()->company->reportsToCompany()->siteList()->pluck('id')->toArray();
     $sites = Site::whereIn('id', $allowedSites)->where('status', '<>', '0')->orderBy('name')->get();
     $array = [];
     $array[] = ['value' => '', 'text' => 'Select site'];
     // Create array in specific Vuejs 'select' format.
     $tobeallocated = User::find(136);
     foreach ($sites as $site) {
         if ($site->isUserSupervisor($tobeallocated)) {
             $array[] = ['value' => $site->id, 'text' => $site->name, 'name' => $site->name];
         }
     }
     return $array;
 }
예제 #12
0
 /**
  * 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'));
 }
예제 #13
0
 /**
  * Display a listing of the resource.
  *
  * @return \Illuminate\Http\Response
  */
 public function index(Request $request)
 {
     if ($request->ajax()) {
         $site_list = [];
         // Allow Supervisor only to view their sites
         if (Auth::user()->is('supervisor')) {
             $site_list = Auth::user()->supervisorSiteList()->pluck('id')->toArray();
         } else {
             if (Auth::user()->is('full.access|full.read.access|general.admin|whs.admin|construction.manager')) {
                 $site_list = Auth::user()->company->siteList()->pluck('id')->toArray();
             }
         }
         $compliance_recs = SiteCompliance::whereIn('site_id', $site_list)->get();
         $compliance = [];
         $sites = [];
         $users = [];
         foreach ($compliance_recs as $comply) {
             $array = [];
             $array['id'] = $comply->id;
             // Site Info - Array of unique sites (stores previous sites to speed up)
             if (isset($sites[$comply->site_id])) {
                 $site = $sites[$comply->site_id];
                 $supers = $site->supers;
             } else {
                 $site = Site::find($comply->site_id);
                 $sites[$comply->site_id] = (object) ['id' => $site->id, 'name' => $site->name, 'supers' => $site->supervisorsSeparatedByComma()];
                 $supers = $site->supervisorsSeparatedByComma();
             }
             $array['site_id'] = $site->id;
             $array['site_name'] = $site->name;
             $array['site_supers'] = $supers;
             // User Info - Array of unique users (store previous users to speed up)
             if (isset($users[$comply->user_id])) {
                 $user = $users[$comply->user_id];
                 $company_name = $user->company_name;
             } else {
                 $user = User::find($comply->user_id);
                 $users[$comply->user_id] = (object) ['id' => $user->id, 'full_name' => $user->full_name, 'company_name' => $user->company->name];
                 $company_name = $user->company->name;
             }
             $array['user_id'] = $user->id;
             $array['user_name'] = $user->full_name;
             $array['user_company'] = $company_name;
             //$array['reason_name'] = $comply->name;
             $reason = $comply->reason;
             if ($comply->reason == null) {
                 $reason = '';
             }
             $array['reason'] = $reason;
             $array['date'] = $comply->date->format('Y-m-d');
             $array['resolved_date'] = $comply->resolved_date->format('Y-m-d');
             $array['status'] = $comply->status;
             $array['notes'] = $comply->notes;
             $compliance[] = $array;
         }
         // Reasons array in specific Vuejs 'select' format.
         $reason_recs = SiteComplianceReason::where('status', '1')->where('company_id', Auth::user()->company->id)->orderBy('name')->get();
         $reasons = [];
         $reasons[] = ['value' => '', 'text' => 'Unassigned Reason'];
         foreach ($reason_recs as $reason) {
             $reasons[] = ['value' => $reason->id, 'text' => $reason->name, 'name' => $reason->name];
         }
         $json = [];
         $json[] = $compliance;
         $json[] = $reasons;
         return $json;
     }
     // Check authorisation and throw 404 if not
     if (!Auth::user()->can(allPermissionTypeString('compliance'))) {
         return view('errors/404');
     }
     return view('site/compliance/list');
 }
예제 #14
0
 public function jobstartPDF(Request $request)
 {
     $today = Carbon::now()->format('Y-m-d');
     $planner = DB::table('site_planner AS p')->select(['p.id', 'p.site_id', 'p.entity_type', 'p.entity_id', 'p.task_id', 'p.from', 't.code'])->join('trade_task as t', 'p.task_id', '=', 't.id')->whereDate('p.from', '>=', $today)->where('t.code', 'START')->orderBy('p.from')->get();
     //dd($planner);
     $startdata = [];
     foreach ($planner as $plan) {
         $site = Site::findOrFail($plan->site_id);
         $entity_name = "Carpenter";
         if ($plan->entity_type == 'c') {
             $entity_name = Company::find($plan->entity_id)->name;
         }
         $startdata[] = ['date' => Carbon::createFromFormat('Y-m-d H:i:s', $plan->from)->format('M j'), 'code' => $site->code, 'name' => $site->name, 'company' => $entity_name];
     }
     $pdf = PDF::loadView('pdf/plan-jobstart', compact('startdata'));
     if ($request->has('view_pdf')) {
         return $pdf->stream();
     }
     if ($request->has('email_pdf')) {
         /*$file = public_path('filebank/tmp/jobstart-' . Auth::user()->id  . '.pdf');
           if (file_exists($file))
               unlink($file);
           $pdf->save($file);*/
         if ($request->get('email_list')) {
             $email_list = explode(';', $request->get('email_list'));
             $email_list = array_map('trim', $email_list);
             // trim white spaces
             $data = ['user_fullname' => Auth::user()->fullname, 'user_company_name' => Auth::user()->company->name, 'startdata' => $startdata];
             Mail::send('emails/jobstart', $data, function ($m) use($email_list, $data) {
                 $user_email = Auth::user()->email;
                 $user_email ? $send_from = $user_email : ($send_from = '*****@*****.**');
                 $m->from($send_from, Auth::user()->fullname);
                 $m->to($email_list);
                 $m->subject('Upcoming Job Start Dates');
             });
             if (count(Mail::failures()) > 0) {
                 foreach (Mail::failures as $email_address) {
                     Toastr::error("Failed to send to {$email_address}");
                 }
             } else {
                 Toastr::success("Sent email");
             }
             return view('planner/export/start');
         }
     }
 }
예제 #15
0
 public static function roster()
 {
     $log = '';
     echo "<h2>Adding Users to Roster</h2>";
     $log .= "Adding New Users to Roster\n";
     $log .= "------------------------------------------------------------------------\n\n";
     $allowedSites = Site::all()->pluck('id')->toArray();
     if (Auth::check()) {
         $allowedSites = Auth::user()->company->siteList('1')->pluck('id')->toArray();
     }
     $date = Carbon::now()->format('Y-m-d');
     //$date = '2016-08-17';
     $planner = SitePlanner::where('from', '<=', $date)->where('to', '>=', $date)->whereIn('site_id', $allowedSites)->orderBy('site_id')->get();
     foreach ($planner as $plan) {
         if ($plan->entity_type == 'c') {
             $site = Site::find($plan->site_id);
             $company = Company::findOrFail($plan->entity_id);
             $staff = $company->staffActive()->pluck('id')->toArray();
             $task = Task::find($plan->task_id);
             echo "<br><b>Site:{$site->name} ({$plan->site_id}) &nbsp; Company: {$company->name} &nbsp; Task: {$task->name} &nbsp; PID: {$plan->id}</b><br>";
             $log .= "\nSite: {$site->name} ({$plan->site_id}) Company: {$company->name}  Task: {$task->name} PID: {$plan->id}\n";
             $found = false;
             foreach ($staff as $staff_id) {
                 $user = User::findOrFail($staff_id);
                 if (!$site->isUserOnRoster($staff_id, $date)) {
                     echo 'adding ' . $user->fullname . ' (' . $user->username . ') to roster<br>';
                     $log .= 'adding ' . $user->fullname . ' (' . $user->username . ") to roster\n";
                     $newRoster = SiteRoster::create(array('site_id' => $site->id, 'user_id' => $staff_id, 'date' => $date . ' 00:00:00', 'created_by' => '1', 'updated_by' => '1'));
                     $found = true;
                 }
             }
             if (!$found) {
                 echo "There were no users to add or they were already on the roster<br>";
                 $log .= "There were no users to add or they were already on the roster\n";
             }
         }
     }
     echo "<h4>Completed</h4>";
     $log .= "\nCompleted\n\n\n";
     $bytes_written = File::append(public_path('filebank/log/nightly/' . Carbon::now()->format('Ymd') . '.txt'), $log);
     if ($bytes_written === false) {
         die("Error writing to file");
     }
 }
예제 #16
0
 /**
  * Get Sites current user is authorised to manage + Process datatables ajax request.
  */
 public function getIssues(Request $request)
 {
     //$site_list = Auth::user()->company->reportsToCompany()->siteList()->pluck('id')->toArray();
     $site_list = [];
     // Allow Supervisor + Construction Manager to view their sites
     if (Auth::user()->is('construction.manager')) {
         $site_list = Auth::user()->company->siteList()->pluck('id')->toArray();
     } else {
         if (Auth::user()->is('supervisor')) {
             $site_list = Auth::user()->supervisorSiteList()->pluck('id')->toArray();
         }
     }
     $user_list = [Auth::user()->id];
     // Allow senior users with full access, WHS or child companies leading hand/admin to view their own users reports
     if (Auth::user()->can('view.issue.report|view.p.issue.report') && Auth::user()->is('full.access|full.read.access|whs.admin|leading.hand|contractor.admin')) {
         $user_list = Auth::user()->company->userList()->pluck('id')->toArray();
     }
     $issue_records = SiteIssue::select(['site_issues.id', 'site_issues.site_id', 'site_issues.created_by', DB::raw('DATE_FORMAT(site_issues.created_at, "%d/%m/%y") AS nicedate'), DB::raw('CONCAT(users.firstname, " ", users.lastname) AS fullname'), 'site_issues.reason', 'site_issues.action_required', 'site_issues.photo', 'site_issues.status', 'site_issues.resolved_date', 'sites.name', 'sites.code'])->join('sites', 'site_issues.site_id', '=', 'sites.id')->join('users', 'site_issues.created_by', '=', 'users.id')->where('site_issues.status', '=', $request->get('status'))->where(function ($q) use($site_list, $user_list) {
         $q->whereIn('site_issues.created_by', $user_list);
         $q->orWhereIn('site_id', $site_list);
     });
     //->orderBy('site_issues.created_at', 'DESC');
     $dt = Datatables::of($issue_records)->addColumn('view', function ($issue) {
         return '<div class="text-center"><a href="/site/safety-issue/' . $issue->id . '"><i class="fa fa-search"></i></a></div>';
     })->addColumn('supervisor', function ($issue) {
         $s = Site::find($issue->site_id);
         return $s->supervisorsSeparatedByComma();
     })->editColumn('action_required', function ($issue) {
         return $issue->action_required ? 'Yes' : 'No';
     })->editColumn('photo', function ($issue) {
         if ($issue->photo && file_exists('filebank/site/' . $issue->site_id . '/issue/' . $issue->photo)) {
             return '<a href="/filebank/site/' . $issue->site_id . '/issue/' . $issue->photo . '" data-lity class="html5lightboxXXXX btn btn-xs blue"><i class="fa fa-picture-o"></a>';
         }
         return '';
     })->filterColumn('fullname', 'whereRaw', "CONCAT(users . firstname, ' ', users . lastname) like ? ", [" % \$1 % "])->make(true);
     return $dt;
 }
예제 #17
0
파일: Company.php 프로젝트: unclefudge/whs
 /**
  * A dropdown list of sites this company is on a Planner for
  *
  * @return array
  */
 public function sitePlannerListSelect($prompt = '', $status = '1')
 {
     $array = [];
     foreach ($this->sitePlannerList($status) as $site) {
         $record = Site::findOrFail($site->id);
         if ($record->status) {
             $array[$site->id] = $record->name;
         }
     }
     asort($array);
     return $prompt && count($array) > 1 ? $array = array('' => 'Select Site') + $array : $array;
 }
예제 #18
0
 /**
  * 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'));
 }