コード例 #1
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'));
 }
コード例 #2
0
ファイル: SiteRoster.php プロジェクト: unclefudge/whs
 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;
 }
コード例 #3
0
ファイル: SiteController.php プロジェクト: unclefudge/whs
 /**
  * Get basic Site details.
  */
 public function getSiteOwner($id)
 {
     $site = Site::find($id);
     return $site->client->clientOfCompany;
 }
コード例 #4
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;
 }
コード例 #5
0
 /**
  * Get Sites that given Company is planned for on specified date
  */
 public function getCompanySitesOnDate(Request $request, $company_id, $site_id, $date, $json = 'json')
 {
     $planner = SitePlanner::where('site_id', '<>', $site_id)->where('entity_type', 'c')->where('entity_id', $company_id)->whereDate('from', '<=', $date)->whereDate('to', '>=', $date)->get();
     if ($company_id == '59') {
         //echo "cid:59 site_id:$site_id date:$date json:$json<br>";
         //var_dump($planner);
     }
     $sites = [];
     foreach ($planner as $plan) {
         $array = [];
         $task_code = '';
         if ($plan->task_id) {
             $task = Task::find($plan->task_id);
             $task_code = $task->code;
         }
         if (array_key_exists($plan->site_id, $sites)) {
             $sites[$plan->site_id] .= ', ' . $task_code;
         } else {
             $site = Site::find($plan->site_id);
             $sites[$plan->site_id] = substr($site->name, 0, 8) . ' - ' . $task_code;
         }
     }
     $str = '';
     if ($sites) {
         foreach ($sites as $key => $value) {
             if ($json == 'json') {
                 $str .= $value . ', ';
             } else {
                 $str .= $value . '<br>';
             }
         }
         if ($json == 'json') {
             $str = rtrim($str, ', ');
         } else {
             $str = rtrim($str, '<br>');
         }
     }
     //if ($company_id == '59')
     //   dd($str);
     if ($json == 'json') {
         return $str;
     } else {
         return $str;
     }
 }
コード例 #6
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');
 }
コード例 #7
0
 public function sitePDF(SitePlannerExportRequest $request, $site_id, $date, $weeks)
 {
     $date = Carbon::createFromFormat('d/m/Y H:i:s', $request->get('date') . ' 00:00:00')->format('Y-m-d');
     $weeks = $request->get('weeks');
     /*
      * Export by Company
      */
     if ($request->has('export_site')) {
         $site_id = $request->get('site_id');
         //echo "Site: $site_id Date: $date Weeks: $weeks<br>";
         //exit();
         $sites = [];
         if ($site_id) {
             $sites[] = $site_id;
         } else {
             $sites = Auth::user()->company->reportsToCompany()->siteList('1')->pluck('id')->toArray();
         }
         // Sort Sites by Site Name
         $site_list = [];
         foreach ($sites as $siteID) {
             $site_list[$siteID] = Site::find($siteID)->name;
         }
         asort($site_list);
         // For each Site get Tasks om Planner
         $sitedata = [];
         foreach ($site_list as $siteID => $siteName) {
             $site = Site::findOrFail($siteID);
             $obj_site = (object) [];
             $obj_site->site_id = $site->id;
             $obj_site->site_name = $site->name;
             $obj_site->weeks = [];
             // For each week get Entities on the Planner
             $current_date = $date;
             for ($w = 1; $w <= $weeks; $w++) {
                 $date_from = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00');
                 if ($date_from->isWeekend()) {
                     $date_from->addDays(1);
                 }
                 if ($date_from->isWeekend()) {
                     $date_from->addDays(1);
                 }
                 // Calculate Date to ensuring not a weekend
                 $date_to = Carbon::createFromFormat('Y-m-d H:i:s', $date_from->format('Y-m-d H:i:s'));
                 $dates = [$date_from->format('Y-m-d')];
                 for ($i = 2; $i < 6; $i++) {
                     $date_to->addDays(1);
                     if ($date_to->isWeekend()) {
                         $date_to->addDays(2);
                     }
                     $dates[] = $date_to->format('Y-m-d');
                 }
                 //echo "From: " . $date_from->format('d/m/Y') . " To:" . $date_to->format('d/m/Y') . "<br>";
                 $planner = SitePlanner::select(['id', 'site_id', 'entity_type', 'entity_id', 'task_id', 'from', 'to', 'days'])->where(function ($q) use($date_from, $date_to, $site) {
                     $q->where('from', '>=', $date_from->format('Y-m-d'));
                     $q->Where('from', '<=', $date_to->format('Y-m-d'));
                     $q->where('site_id', $site->id);
                 })->orWhere(function ($q) use($date_from, $date_to, $site) {
                     $q->where('to', '>=', $date_from->format('Y-m-d'));
                     $q->Where('to', '<=', $date_to->format('Y-m-d'));
                     $q->where('site_id', $site->id);
                 })->orWhere(function ($q) use($date_from, $date_to, $site) {
                     $q->where('from', '<', $date_from->format('Y-m-d'));
                     $q->Where('to', '>', $date_to->format('Y-m-d'));
                     $q->where('site_id', $site->id);
                 })->orderBy('from')->get();
                 // Get Unique list of Entities for current week
                 $entities = [];
                 foreach ($planner as $plan) {
                     $key = $plan->entity_type . '.' . $plan->entity_id;
                     if (!isset($entities[$key])) {
                         $entity_name = $plan->entity_type == 'c' ? Company::find($plan->entity_id)->name : Trade::find($plan->entity_id)->name;
                         $entities[$key] = ['key' => $key, 'entity_type' => $plan->entity_type, 'entity_id' => $plan->entity_id, 'entity_name' => $entity_name];
                         for ($i = 0; $i < 5; $i++) {
                             $entities[$key][$dates[$i]] = '';
                         }
                     }
                 }
                 usort($entities, 'sortEntityName');
                 // Create Header Row for Current Week
                 $obj_site->weeks[$w] = [];
                 $obj_site->weeks[$w][0][] = 'COMPANY';
                 foreach ($dates as $d) {
                     $obj_site->weeks[$w][0][] = strtoupper(Carbon::createFromFormat('Y-m-d H:i:s', $d . ' 00:00:00')->format('l d/m'));
                 }
                 // For each Entity on for current week get their Tasks for each day of the week
                 $entity_count = 1;
                 if ($entities) {
                     foreach ($entities as $e) {
                         $obj_site->weeks[$w][$entity_count][] = $e['entity_name'];
                         for ($i = 1; $i <= 5; $i++) {
                             $tasks = $site->entityTasksOnDate($e['entity_type'], $e['entity_id'], $dates[$i - 1]);
                             if ($tasks) {
                                 $str = '';
                                 foreach ($tasks as $task_id => $task_name) {
                                     $str .= $task_name . '<br>';
                                 }
                             } else {
                                 $str = '&nbsp;';
                             }
                             $obj_site->weeks[$w][$entity_count][$i] = $str;
                         }
                         $entity_count++;
                     }
                 } else {
                     $obj_site->weeks[$w][1][] = 'NOTHING-ON-PLAN';
                     $obj_site->weeks[$w][1][1] = '';
                 }
                 $date_next = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00')->addDays(7);
                 $current_date = $date_next->format('Y-m-d');
             }
             $sitedata[] = $obj_site;
         }
         //return view('pdf.plan-site', compact('site', 'date', 'weeks', 'sitedata'));
         $pdf = PDF::loadView('pdf.plan-site', compact('site', 'date', 'weeks', 'sitedata'))->setOption('page-width', 200)->setOption('page-height', 287)->setOption('margin-bottom', 10)->setOrientation('landscape');
         //$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();
     }
     /*
      * Export by Company
      */
     if ($request->has('export_company')) {
         $company_id = $request->get('company_id');
         $companies = [];
         if ($company_id) {
             $companies[] = $company_id;
         } else {
             $companies = Auth::user()->company->companyList('1')->pluck('id')->toArray();
         }
         // Sort Companies by Name
         $company_list = [];
         foreach ($companies as $cid) {
             $company_list[$cid] = Company::find($cid)->name;
         }
         asort($company_list);
         // For each Company get Tasks om Planner
         $sitedata = [];
         foreach ($company_list as $cid => $cname) {
             $company = Company::find($cid);
             $obj_site = (object) [];
             $obj_site->company_id = $company->id;
             $obj_site->company_name = $company->name;
             $obj_site->weeks = [];
             $obj_site->upcoming = [];
             // For each week get Sites on the Planner
             $current_date = $date;
             for ($w = 1; $w <= $weeks; $w++) {
                 $date_from = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00');
                 if ($date_from->isWeekend()) {
                     $date_from->addDays(1);
                 }
                 if ($date_from->isWeekend()) {
                     $date_from->addDays(1);
                 }
                 // Calculate Date To ensuring not a weekend
                 $date_to = Carbon::createFromFormat('Y-m-d H:i:s', $date_from->format('Y-m-d H:i:s'));
                 $dates = [$date_from->format('Y-m-d')];
                 for ($i = 2; $i < 6; $i++) {
                     $date_to->addDays(1);
                     if ($date_to->isWeekend()) {
                         $date_to->addDays(2);
                     }
                     $dates[] = $date_to->format('Y-m-d');
                 }
                 //echo "From: " . $date_from->format('d/m/Y') . " To:" . $date_to->format('d/m/Y') . "<br>";
                 $planner = SitePlanner::select(['id', 'site_id', 'entity_type', 'entity_id', 'task_id', 'from', 'to', 'days'])->where(function ($q) use($date_from, $date_to, $company) {
                     $q->where('from', '>=', $date_from->format('Y-m-d'));
                     $q->Where('from', '<=', $date_to->format('Y-m-d'));
                     $q->where('entity_type', 'c');
                     $q->where('entity_id', $company->id);
                 })->orWhere(function ($q) use($date_from, $date_to, $company) {
                     $q->where('to', '>=', $date_from->format('Y-m-d'));
                     $q->Where('to', '<=', $date_to->format('Y-m-d'));
                     $q->where('entity_type', 'c');
                     $q->where('entity_id', $company->id);
                 })->orWhere(function ($q) use($date_from, $date_to, $company) {
                     $q->where('from', '<', $date_from->format('Y-m-d'));
                     $q->Where('to', '>', $date_to->format('Y-m-d'));
                     $q->where('entity_type', 'c');
                     $q->where('entity_id', $company->id);
                 })->orderBy('from')->get();
                 // Get Unique list of Sites for current week
                 $sites = [];
                 foreach ($planner as $plan) {
                     if (!isset($sites[$plan->site_id])) {
                         $site = Site::find($plan->site_id);
                         $sites[$plan->site_id] = ['site_id' => $plan->site_id, 'site_name' => $site->name, 'site_supervisor' => $site->supervisorsFirstNameSeparatedByComma()];
                         for ($i = 0; $i < 5; $i++) {
                             $sites[$plan->site_id][$dates[$i]] = '';
                         }
                     }
                 }
                 usort($sites, 'sortSiteName');
                 // Create Header Row for Current Week
                 $obj_site->weeks[$w] = [];
                 $obj_site->weeks[$w][0][] = 'SITE';
                 foreach ($dates as $d) {
                     $obj_site->weeks[$w][0][] = strtoupper(Carbon::createFromFormat('Y-m-d H:i:s', $d . ' 00:00:00')->format('l d/m'));
                 }
                 // For each Site on for current week get the Company Tasks for each day of the week
                 $site_count = 1;
                 if ($sites) {
                     foreach ($sites as $s) {
                         $obj_site->weeks[$w][$site_count][] = $s['site_name'] . ' (' . $s['site_supervisor'] . ')';
                         for ($i = 1; $i <= 5; $i++) {
                             $site = Site::find($s['site_id']);
                             $tasks = $site->entityTasksOnDate('c', $company->id, $dates[$i - 1]);
                             if ($tasks) {
                                 $str = '';
                                 foreach ($tasks as $task_id => $task_name) {
                                     $str .= $task_name . '<br>';
                                 }
                             } else {
                                 $str = '&nbsp;';
                             }
                             $obj_site->weeks[$w][$site_count][$i] = $str;
                         }
                         $site_count++;
                     }
                 } else {
                     $obj_site->weeks[$w][1][] = 'NOTHING-ON-PLAN';
                     $obj_site->weeks[$w][1][1] = '';
                 }
                 $date_next = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00')->addDays(7);
                 $current_date = $date_next->format('Y-m-d');
             }
             /*
              * Upcoming
              */
             //for ($w = 1; $w <= 2; $w++) {
             $date_from = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00');
             $date_to = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00');
             $date_to->addDays(14);
             //echo "From: " . $date_from->format('d/m/Y') . " To:" . $date_to->format('d/m/Y') . "<br>";
             $planner = SitePlanner::select(['id', 'site_id', 'entity_type', 'entity_id', 'task_id', 'from', 'to', 'days'])->where(function ($q) use($date_from, $date_to, $company) {
                 $q->where('from', '>=', $date_from->format('Y-m-d'));
                 $q->Where('from', '<=', $date_to->format('Y-m-d'));
                 $q->where('entity_type', 'c');
                 $q->where('entity_id', $company->id);
             })->orWhere(function ($q) use($date_from, $date_to, $company) {
                 $q->where('to', '>=', $date_from->format('Y-m-d'));
                 $q->Where('to', '<=', $date_to->format('Y-m-d'));
                 $q->where('entity_type', 'c');
                 $q->where('entity_id', $company->id);
             })->orWhere(function ($q) use($date_from, $date_to, $company) {
                 $q->where('from', '<', $date_from->format('Y-m-d'));
                 $q->Where('to', '>', $date_to->format('Y-m-d'));
                 $q->where('entity_type', 'c');
                 $q->where('entity_id', $company->id);
             })->orderBy('from')->get();
             //dd($planner);
             $sites = [];
             foreach ($planner as $plan) {
                 if (!in_array($plan->site_id, $sites)) {
                     $sites[] = $plan->site_id;
                 }
             }
             $current_date = Carbon::createFromFormat('Y-m-d H:i:s', $current_date . ' 00:00:00');
             if ($sites) {
                 for ($x = 1; $x <= 14; $x++) {
                     // Skip Weekends
                     if ($current_date->isWeekend()) {
                         $current_date->addDays(1);
                     }
                     if ($current_date->isWeekend()) {
                         $current_date->addDays(1);
                     }
                     foreach ($sites as $s) {
                         $site = Site::find($s);
                         $tasks = $site->entityTasksOnDate('c', $company->id, $current_date->format('Y-m-d'));
                         if ($tasks) {
                             $task_list = '';
                             foreach ($tasks as $task_id => $task_name) {
                                 $task_list .= $task_name . ', ';
                             }
                             $task_list = rtrim($task_list, ', ');
                             $obj_site->upcoming[] = ['date' => $current_date->format('M j'), 'site' => $site->name, 'tasks' => $task_list];
                         }
                     }
                     $current_date->addDay(1);
                 }
             }
             //}
             $sitedata[] = $obj_site;
         }
         //dd($sitedata);
         //return view('pdf/plan-company', compact('company_id', 'date', 'weeks', 'sitedata'));
         $pdf = PDF::loadView('pdf.plan-company', compact('company_id', 'date', 'weeks', 'sitedata'))->setOption('page-width', 200)->setOption('page-height', 287)->setOption('margin-bottom', 10)->setOrientation('landscape');
         //$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();
     }
 }
コード例 #8
0
ファイル: CronController.php プロジェクト: unclefudge/whs
 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");
     }
 }