コード例 #1
0
ファイル: Kernel.php プロジェクト: leanne-abarro/tagAndTrack
 /**
  * Define the application's command schedule.
  *
  * @param  \Illuminate\Console\Scheduling\Schedule  $schedule
  * @return void
  */
 protected function schedule(Schedule $schedule)
 {
     // 5 day notice
     $schedule->call(function () {
         $FiveDaystoGo = \Carbon\Carbon::now()->addDays(5)->format("Y-m-d");
         $usertools = \App\Models\Tool::where("retag_date", "=", $FiveDaystoGo)->where("five_notice", "=", "0")->get();
         foreach ($usertools as $tool) {
             $notification = new \App\Models\Notification();
             $notification->message = '<a href="' . url("industryProject/public/tools/" . $tool->id) . '">' . $tool->name . '</a>' . " is due for re-tagging within the next five days.";
             $notification->user_id = $tool->user_id;
             $notification->save();
             $tool->five_notice = 1;
             $tool->save();
         }
         //send email
         Mail::send('emails.fiveNotice', ['tool' => $tool], function ($m) {
             $m->from('*****@*****.**', 'Tag and Track');
             $m->to('*****@*****.**', 'Leanne')->subject('Tool is due to be re-tagged.');
         });
     })->dailyAt('04:00');
     // 3 day notice
     $schedule->call(function () {
         $ThreeDaystoGo = \Carbon\Carbon::now()->addDays(3)->format("Y-m-d");
         $usertools = \App\Models\Tool::where("retag_date", "=", $ThreeDaystoGo)->where("three_notice", "=", "0")->get();
         foreach ($usertools as $tool) {
             $notification = new \App\Models\Notification();
             $notification->message = '<a href="' . url("industryProject/public/tools/" . $tool->id) . '">' . $tool->name . '</a>' . " is due for re-tagging within the next three days.";
             $notification->user_id = $tool->user_id;
             $notification->save();
             $tool->three_notice = 1;
             $tool->save();
         }
         //send email
         Mail::send('emails.threeNotice', ['tool' => $tool], function ($m) {
             $m->from('*****@*****.**', 'Tag and Track');
             $m->to('*****@*****.**', 'Leanne')->subject('Tool is due to be re-tagged.');
         });
     })->dailyAt('05:00');
     // 1 day notice
     $schedule->call(function () {
         $OneDaytoGo = \Carbon\Carbon::now()->addDays(1)->format("Y-m-d");
         $usertools = \App\Models\Tool::where("retag_date", "=", $OneDaytoGo)->where("one_notice", "=", "0")->get();
         foreach ($usertools as $tool) {
             $notification = new \App\Models\Notification();
             $notification->message = '<a href="' . url("industryProject/public/tools/" . $tool->id) . '">' . $tool->name . '</a>' . " is due for re-tagging tomorrow.";
             $notification->user_id = $tool->user_id;
             $notification->save();
             $tool->one_notice = 1;
             $tool->save();
         }
         //send email
         Mail::send('emails.oneNotice', ['tool' => $tool], function ($m) {
             $m->from('*****@*****.**', 'Tag and Track');
             $m->to('*****@*****.**', 'Leanne')->subject('Tool is due to be re-tagged.');
         });
     })->dailyAt('06:00');
 }
コード例 #2
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     App\Models\Notification::create(['notified' => 0, 'alarm' => '2015-11-12 11:50:00', 'shop_id' => 1]);
     $faker = Faker::create();
     foreach (range(1, 30) as $i) {
         App\Models\Notification::create(['notified' => $faker->numberBetween(0, 1), 'alarm' => $faker->dateTimeBetween('now', '+30 days'), 'shop_id' => $i]);
     }
 }
コード例 #3
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(UpdateToolRequest $request, $id)
 {
     //
     $tool = \App\Models\Tool::find($id);
     $tool->fill($request->all());
     $type = \Request::get("type");
     // if company tool has been transferred
     $iPreviousSiteID = $tool->user->site_id;
     if ($tool->user->site_id != $request->get("site_id")) {
         $iNewSiteID = \App\Models\Site::find($request->get("site_id"))->users()->where("admin", "=", "Yes")->first()->site_id;
         $tool->user_id = \App\Models\Site::find($request->get("site_id"))->users()->where("admin", "=", "Yes")->first()->id;
         // send notification
         $notification = new \App\Models\Notification();
         $notification->message = '<a href="' . url("tools/" . $tool->id) . '">' . $tool->name . '</a>' . " has been transferred to this job site.";
         $notification->user_id = $tool->user_id;
         $notification->save();
         //send email
         Mail::send('emails.transfers', ['tool' => $tool], function ($m) {
             $m->from('*****@*****.**', 'Tag and Track');
             $m->to('*****@*****.**', 'Leanne')->subject('Company Tool has been transferred');
         });
         // transfers table
         $transfer = new \App\Models\Transfer();
         $transfer->previous_site_id = $iPreviousSiteID;
         $transfer->current_site_id = $iNewSiteID;
         $transfer->tool_id = $tool->id;
         $transfer->save();
     }
     // reset notifications flags, when retag date changes
     if ($tool->retag_date != $request->get("retag_date")) {
         $tool->five_notice = 0;
         $tool->three_notice = 0;
         $tool->one_notice = 0;
     }
     $tool->save();
     if ($request->has('tech_name')) {
         $name = $request->get('tech_name');
         $company = $request->get('tech_company');
         $phone = $request->get('contact_number');
         $technician = \App\Models\Technician::where("tech_name", '=', $name)->where("tech_company", '=', $company)->where("contact_number", '=', $phone)->first();
         // if technician doesn't exist
         if ($technician == false) {
             $technician = Technician::create($request->all());
         }
         $tool->technician_id = $technician->id;
         $tool->save();
     }
     if ($type == "Company") {
         return redirect('tools?type=Company')->with('message-update', 'Update successful.');
     } else {
         return redirect('tools?type=Personal')->with('message-update', 'Update successful.');
     }
 }