public function index(Request $request) { $query = new Notification(); $companyId = $request->input('companyId'); $orderNumber = $request->input('orderNumber'); $type = $request->input('type'); $from = $request->input('from'); $to = $request->input('to'); if ($companyId) { $query = $query->where('company_id', $companyId); } if ($orderNumber) { $query = $query->where('order_number', $orderNumber); } if ($type) { $query = $query->where('type', $type); } if ($from) { $query = $query->where('created_at', '>=', $from); } if ($to) { $query = $query->where('updated_at', '<=', $to); } $notifications = $query->paginate(); $companies = Company::all(); $types = Notification::$types; return view('admin::notifications.index', ['notifications' => $notifications, 'companies' => $companies, 'types' => $types, 'company_id' => $companyId, 'type' => $type, 'from' => $from, 'to' => $to, 'order_number' => $orderNumber]); }
/** * Login as the * * @param $companyId * @return \Illuminate\Http\RedirectResponse */ public function loginAs($companyId) { $company = Company::findOrFail($companyId); $user = $company->users()->first(); Auth::admin()->impersonate('user', $user->id); return redirect()->route('user.dashboard'); }
/** * Get the canceled order numbers * * @param $state * @param null $orderNumber * @return mixed */ public static function getCanceled($state, $orderNumber = null, $page) { $perPage = 10; $companyIds = []; if (Auth::admin()->check()) { $companyIds = Company::all()->lists('id')->toArray(); } elseif (Auth::user()->check()) { $companyIds = [Auth::user()->get()->company->id]; } $query = DB::table('canceled_orders')->whereIn('company_id', $companyIds)->take($perPage)->skip($perPage * ($page - 1)); switch ($state) { case 'unconfirmed': $query = $query->where('confirmed', false)->where('denied', false); break; case 'confirmed': $query = $query->where('confirmed', true); break; case 'denied': $query = $query->where('denied', true)->where('confirmed_denied', false); break; } if ($orderNumber) { $query = $query->where('order_number', $orderNumber); } return $query->lists('order_number'); }
/** * Handle the event. * * @return void */ public function handle(ProductCanceledEvent $event) { $company = Company::where('nav_code', $event->navCode)->first(); $canceledOrder = DB::table('canceled_orders')->where('order_number', $event->orderNumber)->first(); if ($canceledOrder) { DB::table('canceled_products')->insert(['canceled_order_id' => $canceledOrder->id, 'product_number' => $event->productNumber, 'product_key' => $event->productKey, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]); } else { $canceledOrderId = DB::table('canceled_orders')->insertGetId(['order_number' => $event->orderNumber, 'admin_id' => $event->adminId, 'company_id' => $company->id, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]); DB::table('canceled_products')->insert(['canceled_order_id' => $canceledOrderId, 'product_number' => $event->productNumber, 'product_key' => $event->productKey, 'created_at' => Carbon::now()->toDateTimeString(), 'updated_at' => Carbon::now()->toDateTimeString()]); } }
/** *Get order for admin, with filter * * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function getOrders(Request $request) { $companies = Company::all(); $orderNumber = $request->input('orderNumber', null) ?: null; $confirmed = $request->input('confirmed', false); $navCode = $request->input('navCode', null); $navCodes = $companies->lists('nav_code')->toArray(); $skip = $request->input('skip', ''); //Sending bools as get params... if ($confirmed == 'false') { $confirmed = false; } $orders = $this->navisionService->getAdminSearched($orderNumber, $navCode ?: $navCodes, $confirmed, $skip); return $this->success($orders); }
/** * @param $companyId * @param Request $request * @return \Illuminate\Http\JsonResponse */ public function updateCompany($companyId, Request $request) { $company = Company::where('id', $companyId)->first(); $name = $request->input('name'); $navCode = $request->input('nav_code'); $userData = $request->input('users'); $deletedUsers = $request->input('deleted_users'); $company->name = $name; $company->nav_code = $navCode; $company->save(); $this->updateOrCreateUsers($userData, $company); $this->deleteUsers($deletedUsers); $company->load('users'); return $this->success($company); }
/** * Handle the event. * * @return void */ public function handle(ProductDeniedEvent $event) { $company = Company::where('nav_code', $event->navCode)->first(); $notification = Notification::createProductDenied($company, $event->orderNumber); $this->pusher->trigger('notification-channel', 'notification', json_encode($notification)); }
public function importNotifications() { //TODO::do we really need to import this? $notifications = DB::connection('old')->table('user_notifications')->get(); foreach ($notifications as $notification) { $company = Company::findOrFail($notification->company_id); $orderNumber = $notification->reference; switch ($notification->type) { case 'add_notes': break; case 'cancel_order': break; case 'change_order': break; case 'confirm_canceled_order': break; case 'deny_order': break; case 'uncancel_order': break; } } }