예제 #1
0
 public static function nonattendees()
 {
     $log = '';
     $yesterday = Carbon::now()->subDays(1);
     $lastweek = Carbon::now()->subDays(7);
     echo "<h2>Adding Non-Attendees to the Non-Logged in list (" . $lastweek->format('d/m/Y') . ' - ' . $yesterday->format('d/m/Y') . ")</h2>";
     $log .= "Adding Non-Attendees to the Non-Logged in list (" . $lastweek->format('d/m/Y') . ' - ' . $yesterday->format('d/m/Y') . ")\n";
     $log .= "-------------------------------------------------------------------------\n\n";
     $allowedSites = Site::all()->pluck('id')->toArray();
     if (Auth::check()) {
         $allowedSites = Auth::user()->company->siteList('1')->pluck('id')->toArray();
     }
     $roster = SiteRoster::where('date', '>=', $lastweek->format('Y-m-d'))->where('date', '<=', $yesterday->format('Y-m-d'))->whereIn('site_id', $allowedSites)->orderBy('site_id')->get();
     $found = false;
     foreach ($roster as $rost) {
         $site = Site::find($rost->site_id);
         $user = User::find($rost->user_id);
         $date = Carbon::createFromFormat('Y-m-d H:i:s', $rost->date);
         // if date is weekday
         if ($date->isWeekday()) {
             if (!$site->isUserOnsite($rost->user_id, $rost->date) && !$site->isUserOnCompliance($rost->user_id, $rost->date)) {
                 echo $rost->date->format('d/m/Y') . " {$site->name} ({$site->code}) - <b>{$user->fullname}</b> (" . $user->company->name . ") was absent<br>";
                 $log .= $rost->date->format('d/m/Y') . " {$site->name} ({$site->code}) - {$user->fullname} (" . $user->company->name . ") was absent\n";
                 SiteCompliance::create(array('site_id' => $site->id, 'user_id' => $user->id, 'date' => $rost->date, 'reason' => null, 'status' => 0, 'resolved_date' => '0000-00-00 00:00:00'));
                 $found = true;
             }
         }
     }
     if (!$found) {
         echo "There were no Non-Attendees to add or they were already on the list<br>";
         $log .= "There were no Non-Attendees to add or they were already on the list\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");
     }
 }
예제 #2
0
 /**
  * Migrate Site Comply
  */
 public function comply()
 {
     echo "<h1>Migrating Compliance</h1>";
     DB::table('site_compliance')->truncate();
     set_time_limit(60);
     $complys = zSiteComply::all();
     $complys->each(function ($comply) {
         echo "<b>" . $comply->sub_id . "</b> {$comply->jobnum} - ({$comply->date})";
         $user = User::where('username', $comply->sub_id)->first();
         $site = Site::where('code', $comply->jobnum)->first();
         $user2 = User::where('username', $comply->updated_by)->first();
         if ($user2) {
             $updatedby = $user2->id;
         } else {
             $updatedby = '1';
         }
         $status = '0';
         if ($comply->resolved == "y") {
             $status = '1';
         }
         $reason = null;
         if ($comply->reason == '0') {
             $reason = 12;
         } else {
             if ($comply->reason != '') {
                 $reason = $comply->reason;
             }
         }
         if ($user && $site) {
             $newComply = SiteCompliance::create(array('site_id' => $site->id, 'user_id' => $user->id, 'date' => $comply->date, 'reason' => $reason, 'status' => $status, 'resolved_date' => $comply->resdate, 'notes' => reformatOldStr($comply->notes), 'created_by' => '1', 'updated_by' => $updatedby, 'created_at' => $comply->date, 'updated_at' => $comply->updated));
         } else {
             echo " FAILED";
         }
         echo "<br>";
     });
     echo "<h1>Completed</h1>";
 }