/** * 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'); }
public static function get($x) { $sql = "SELECT * FROM invoices where invoiceID = :x"; $row = DB::SelectOne($sql, ["x" => $x]); $invoice = new Invoice(); $invoice->id = $row->invoiceID; $invoice->date = $row->invoiceDate; $invoice->customer = $row->customer; // I really want an array of items here.... /// How could i possibly fetch the items for just this inovice id???? $invoice->tools = Tool::getByInvoiceId($x); $invoice->calcTotal(); return $invoice; }
/** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { $toolID = $request->route('tools'); $tool = \App\Models\Tool::find($toolID); $toolType = \App\Models\Tool::find($toolID)->type; $userID = \App\Models\Tool::find($toolID)->user_id; // any user trying to access personal tools if ($toolType == "Personal") { if (\Auth::user()->id != $userID) { if ($request->ajax()) { return response('Unauthorized', 401); } else { return redirect()->guest('noAccess'); } } } // any user trying to access company tools if ($toolType == "Company") { // if a user is not an admin or a super if (\Auth::user()->admin == "No" && \Auth::user()->super == "No") { if ($request->ajax()) { return response('Unauthorized', 401); } else { return redirect()->guest('noAccess'); } } // if an admin user is trying to access a company tool that does not belong to their site if (\Auth::user()->admin == "Yes") { if (\Auth::user()->site_id != $tool->user->site_id) { if ($request->ajax()) { return response('Unauthorized', 401); } else { return redirect()->guest('noAccess'); } } } // if a super user is trying to access a company tool that does not belong to their company if (\Auth::user()->super == "Yes") { if (\Auth::user()->site->company_id != $tool->user->site->company_id) { if ($request->ajax()) { return response('Unauthorized', 401); } else { return redirect()->guest('noAccess'); } } } } // end of $toolType == "Company" if statement return $next($request); }
Route::get('countduepersonaltools', function () { $user = \Auth::user(); $FiveDaystoGo = \Carbon\Carbon::now()->addDays(5)->format("Y-m-d"); $usertools = $user->tools()->where('type', 'Personal')->where("retag_date", "<=", $FiveDaystoGo)->count(); return $usertools; }); Route::get('countduecompanytools', function () { $user = \Auth::user(); $FiveDaystoGo = \Carbon\Carbon::now()->addDays(5)->format("Y-m-d"); if ($user->admin == 'Yes') { $companytools = \App\Models\Tool::whereIn("user_id", function ($query) { $query->select('id')->from("users")->where('site_id', \Auth::user()->site_id); })->where("type", "=", "Company")->where("retag_date", "<=", $FiveDaystoGo)->count(); } else { $companytools = \App\Models\Tool::whereIn("user_id", function ($query) { $query->select('users.id')->from("users")->join("sites", "site_id", "=", "sites.id")->where('company_id', \Auth::user()->site->company_id); })->where("type", "=", "Company")->where("retag_date", "<=", $FiveDaystoGo)->count(); } return $companytools; }); Route::get('countusers', function () { $user = \Auth::user(); if ($user->admin == 'Yes') { $users = \App\Models\User::whereIn("id", function ($query) { $query->select('id')->from("users")->where('site_id', \Auth::user()->site_id); })->count(); } else { $users = \App\Models\User::whereIn("id", function ($query) { $query->select('users.id')->from("users")->join("sites", "site_id", "=", "sites.id")->where('company_id', \Auth::user()->site->company_id); })->count(); }
/** * 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.'); } }