示例#1
0
 /**
  * Company Tasks for given site + date
  *
  * @return array
  */
 public function companyTasksForSiteOnDate($company_id, $site_id, $date)
 {
     $carbon_date = Carbon::createFromFormat('Y-m-d H:i:s', $date . ' 00:00:00');
     $weekend = $carbon_date->isWeekend() ? 1 : 0;
     $planner = SitePlanner::where('site_id', $site_id)->whereDate('from', '<=', $date)->whereDate('to', '>=', $date)->where('weekend', $weekend)->get();
     $tasks = [];
     foreach ($planner as $plan) {
         if ($plan->task_id) {
             $task = Task::find($plan->task_id);
             $tasks[$task->id] = $task ? $task->name : 'Task Unassigned';
         }
     }
     return $tasks;
 }
示例#2
0
 /**
  * A list of sites this company is on a Planner for
  *
  * @return \Illuminate\Database\Eloquent\Collection
  */
 public function sitePlannerList($status = '')
 {
     $client_list = $this->reportsToCompany()->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();
     }
     // If Company has no Parent then return full collection
     // ie. a list of all sites of all their own clients
     if (!$this->parentCompany) {
         return $collection;
     }
     $logged_site_id = '';
     if (Session::has('siteID')) {
         $site_code = Session::get('siteID');
         $site = Site::where(['code' => $site_code])->first();
         $logged_site_id = $site->id;
     }
     // Otherwise return a filtered collection of sites that company is on Planner for
     $filteredCollection = [];
     foreach ($collection as $site) {
         $onPlanner = SitePlanner::where('site_id', $site->id)->where('entity_type', 'c')->where('entity_id', $this->id)->first();
         if (!$onPlanner && $site->id != $logged_site_id) {
             $filteredCollection[] = $site->id;
         }
     }
     return $collection->except($filteredCollection);
 }
示例#3
0
文件: Site.php 项目: unclefudge/whs
 /**
  * Company Tasks for given site + date
  *
  * @return array
  */
 public function anyTasksOnDate($date)
 {
     $carbon_date = Carbon::createFromFormat('Y-m-d H:i:s', $date . ' 00:00:00');
     $weekend = $carbon_date->isWeekend() ? 1 : 0;
     $planner = SitePlanner::where('site_id', $this->id)->whereDate('from', '<=', $date)->whereDate('to', '>=', $date)->where('weekend', $weekend)->first();
     $onplan = SitePlanner::where('site_id', $this->id)->whereDate('from', '<=', $date)->whereDate('to', '>=', $date)->where('weekend', $weekend)->first();
     return $planner ? true : false;
 }
示例#4
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;
     }
 }
示例#5
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");
     }
 }
示例#6
0
 /**
  * Migrate Planner
  */
 public function planner($id)
 {
     echo "<h1>Migrating Planner {$id}</h1>";
     //$p1 = zSitePlanner::where('jobnum', '<', '7610')->orderBy('jobnum')->orderBy('date')->get();
     //$p2 = zSitePlanner::where('jobnum', '>=', '7610')->orderBy('jobnum')->orderBy('date')->get();
     //echo "p1:".count($p1)."<br>";
     //echo "p2:".count($p2)."<br>";
     //dd();
     set_time_limit(60);
     if ($id == '1') {
         //disable foreign key check for this connection before running seeders
         DB::statement('SET FOREIGN_KEY_CHECKS=0;');
         DB::table('site_planner')->truncate();
         DB::table('z_lookup_planner')->truncate();
         DB::statement('SET FOREIGN_KEY_CHECKS=1;');
         $planner = zSitePlanner::where('jobnum', '<', '7610')->orderBy('jobnum')->orderBy('date')->get();
     } else {
         $planner = zSitePlanner::where('jobnum', '>=', '7600')->orderBy('jobnum')->orderBy('date')->get();
     }
     $planner->each(function ($plan) {
         if (true) {
             //$plan->jobnum == '7599') {
             $e = "{$plan->id} <b>" . $plan->company_id . "</b> {$plan->jobnum} - ({$plan->date})";
             $site = Site::where('code', $plan->jobnum)->first();
             if ($plan->company_id) {
                 $type = substr($plan->company_id, 0, 1);
                 if ($type == 'T') {
                     $etype = 't';
                     $tid = DB::table('z_lookup_trades')->where('old', substr($plan->company_id, 3))->get();
                     $tid ? $eid = $tid[0]->new : ($eid = 0);
                     $cid = "TRD";
                 } else {
                     $etype = 'c';
                     $cid = DB::table('z_lookup_company')->where('old', $plan->company_id)->get();
                     $cid ? $eid = $cid[0]->new : ($eid = 1);
                 }
             } else {
                 $cid = '';
             }
             $user = User::where('username', $plan->updated_by)->first();
             if ($user) {
                 $updatedby = $user->id;
             } else {
                 $updatedby = '1';
             }
             if (!$cid) {
                 //echo "<b>NO CID</b> - $e <br>";
             } elseif ($site->id) {
                 $tasks = explode(':', $plan->tasks);
                 foreach ($tasks as $task) {
                     if ($task != '') {
                         if ($task == '0') {
                             $task = null;
                         } else {
                             $lookup = DB::table('z_lookup_tasks')->where('old', $task)->get();
                             $task = $lookup[0]->new;
                         }
                         // If date is a weekday check if Company has same Task previous day
                         $planDate = Carbon::createFromFormat('Y-m-d H:i:s', $plan->date);
                         $planDayofWeek = $planDate->dayOfWeek;
                         $dayBefore = $planDate->subDay();
                         if ($planDayofWeek > 0 && $planDayofWeek < 6) {
                             // 6 = Sat  0 = Sun
                             if ($planDayofWeek == 1) {
                                 $dayBefore = $dayBefore->subDays(2);
                             }
                         } else {
                             $dayBefore = Carbon::createFromFormat('Y-m-d H:i:s', $plan->date);
                         }
                         $sameTask = SitePlanner::where('site_id', $site->id)->where('entity_type', $etype)->where('entity_id', $eid)->where('task_id', $task)->where('to', $dayBefore->toDateTimeString())->get();
                         if (count($sameTask) > 0) {
                             $sameTask[0]->to = $plan->date;
                             $sameTask[0]->days++;
                             $sameTask[0]->save();
                             // Add to lookup
                             zLookupPlanner::create(array('old' => $plan->id, 'site_id' => $site->id, 'date' => $plan->date));
                         } else {
                             $newPlanner = SitePlanner::create(array('site_id' => $site->id, 'from' => $plan->date, 'to' => $plan->date, 'days' => '1', 'entity_type' => $etype, 'entity_id' => $eid, 'task_id' => $task, 'created_by' => '1', 'updated_by' => $updatedby, 'created_at' => '0000-00-00 00:00:00', 'updated_at' => $plan->updated));
                             // Add to lookup
                             zLookupPlanner::create(array('old' => $plan->id, 'site_id' => $site->id, 'date' => $plan->date));
                         }
                         //echo "$task - $e <br>";
                     }
                 }
             } else {
                 //echo "<b>No SITE</b> - $e <br>";
             }
             //echo "$e <br>";
         }
     });
     echo "<h1>Completed</h1>";
 }