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; }
/** * 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'); }
public function addCompanyRoster(Request $request, $cid, $site_id, $date) { $staff = Company::findOrFail($cid)->staffActive()->pluck('id')->toArray(); foreach ($staff as $user_id) { $newRoster = SiteRoster::create(array('site_id' => $site_id, 'user_id' => $user_id, 'date' => $date . ' 00:00:00')); } return; }
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}) Company: {$company->name} Task: {$task->name} 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"); } }
/** * Migrate Site Roster */ public function roster() { echo "<h1>Migrating Roster</h1>"; DB::table('site_roster')->truncate(); set_time_limit(180); $rosters = zSiteRoster::all(); $rosters->each(function ($roster) { //echo $roster->id." <b>" . $roster->sub_id . "</b> $roster->planner_id - ($roster->updated)<br>"; echo "."; $user = User::where('username', $roster->sub_id)->first(); $created = User::where('username', $roster->updated_by)->first(); if (!$created) { $created = User::find('1'); } $lookup = DB::table('z_lookup_planner')->where('old', $roster->planner_id)->first(); if ($user && $lookup) { // Check if already existing ie. old planner had bug of multiple entrys so we removing duplicates $date = Carbon::createFromFormat('Y-m-d H:i:s', substr($lookup->date, 0, 10) . ' 00:00:00')->format('Y-m-d'); $exists = SiteRoster::where('site_id', $lookup->site_id)->where('user_id', $user->id)->whereDate('date', '=', $date)->first(); if (!$exists) { $newRoster = SiteRoster::create(array('site_id' => $lookup->site_id, 'user_id' => $user->id, 'date' => $date . ' 00:00:00', 'created_by' => $created->id, 'updated_by' => $created->id, 'created_at' => $roster->updated, 'updated_at' => $roster->updated)); //echo "id:".$newRoster->id." date: ".$date."<br>"; } } }); echo "<h1>Completed</h1>"; }