Exemplo n.º 1
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;
 }
Exemplo n.º 2
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");
     }
 }