Ejemplo n.º 1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     $items = $request->get('items');
     $me = \Auth::user();
     $order = new \App\Order();
     $order->client()->associate($me);
     $my_orders = $me->orders;
     if ($my_orders->isEmpty()) {
         foreach ($me->waiters()->online()->get() as $waiter) {
             \App\Notification::add($me->toArray(), 'serve_me', $waiter);
         }
     } else {
         $my_order = $my_orders->first()->toArray();
         if ($my_order['waiter_id']) {
             $waiter = \App\User::find($my_order['waiter_id']);
             $order->waiter()->associate($waiter);
             \App\Notification::add($me->toArray(), 'serve_me_again', $waiter);
         }
     }
     $order->save();
     foreach ($items as $item) {
         $food = \App\Food::find($item['food']);
         if ($food->category->menu->admin_id == $me->admin_id) {
             $item = new \App\OrderItem($item);
             $item->food()->associate($food);
             $item->order()->associate($order);
             $item->save();
         }
     }
     return $order->load('items.food');
 }
Ejemplo n.º 2
0
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(Request $request, \App\Order $order)
 {
     $me = \Auth::user();
     $client_id = $order->client_id;
     $my_client = $me->clients->where('id', $client_id);
     if (!$my_client->isEmpty()) {
         $status = $request->get('status');
         $orders = $order->client->orders;
         foreach ($orders as $o) {
             if ($status == 1) {
                 $o->waiter()->associate($me);
                 \App\Notification::add($me->toArray(), 'ur_mine', $order->client);
                 foreach ($order->client->waiters()->online()->get() as $waiter) {
                     if ($waiter->id == $me->id) {
                         continue;
                     }
                     \App\Notification::add($order->client->toArray(), 'hes_mine', $waiter);
                 }
             }
             $o->status = $status;
             $o->save();
         }
         return $orders;
     }
 }
Ejemplo n.º 3
0
 public function store(Request $request)
 {
     $me = auth()->user();
     if ($me->is_client && $request['bill_please']) {
         $waiter = $me->orders->first()->load('waiter')->waiter;
         \App\Notification::add($me->toArray(), 'bill_please', $waiter);
     } else {
         auth()->user()->notifications()->update(['status' => 1]);
     }
     return 'OK';
 }
Ejemplo n.º 4
0
 public function update(Request $request, $id = null)
 {
     if ($id == null) {
         $id = Auth::user()->id;
     }
     $rules = ['names' => 'required', 'password' => 'min:5', 'coordinates' => 'required', 'address' => 'required', 'mobile' => 'required', 'birth_date' => 'regex:/[0-9]{2}\\/[0-9]{2}\\/[0-9]{4}/', 'avatar' => 'image|mimes:jpg,jpeg,bmp,png,gif,tiff', 'cv' => 'mimes:doc,docx,ppt,pps,pptx,ppsx,xls,xlsx'];
     $this->validate($request, $rules);
     $avatar_file_name = null;
     $cv_file_name = null;
     if ($request->file('avatar')) {
         $avatar_file_name = Common::randString(6) . "." . $request->file('avatar')->getClientOriginalExtension();
         Storage::put('avatars/' . $avatar_file_name, file_get_contents($request->file('avatar')->getRealPath()));
         ImageResize::load(storage_path("app") . '/avatars/' . $avatar_file_name);
         ImageResize::resizeToWidth(300);
         ImageResize::save();
     }
     if ($request->file('cv')) {
         $cv_file_name = Common::randString(6) . "." . $request->file('cv')->getClientOriginalExtension();
         Storage::put('cv/' . $cv_file_name, file_get_contents($request->file('cv')->getRealPath()));
     }
     $user = User::find($id);
     if ($request->input('password') != null) {
         $user->password = Hash::make($request->input('password'));
     }
     $user->save();
     $info = PersonalInfo::where('user_id', $id)->first();
     $info->names = $request->input('names');
     $info->address = $request->input('address');
     $info->coordinates = $request->input('coordinates');
     $info->mobile = $request->input('mobile');
     $info->gender = $request->input('gender');
     $info->birth_date = $request->input('birth_date');
     $info->home_phone = $request->input('home_phone');
     $info->work_phone = $request->input('work_phone');
     $info->fax = $request->input('fax');
     $info->other = $request->input('other');
     if ($avatar_file_name != null) {
         $info->avatar = $avatar_file_name;
     }
     if ($cv_file_name != null) {
         $info->cv = $cv_file_name;
     }
     $info->save();
     if ($id != Auth::user()->id) {
         Notification::add($id, 'USER_UPDATE_BY_ADMIN', ['admin_id' => Auth::user()->id]);
     }
     if ($request->input('password') != null) {
         Mail::send('emails.editUserPassword', ['user' => $user, 'info' => $info, 'password' => $request->input('password'), 'company' => implode(', ', User::find($id)->company->pluck('name')->toArray())], function ($m) use($user) {
             $m->from('*****@*****.**', 'TIMELINE');
             $m->to($user->email, $user->names)->subject('Your account on TIMELINE platform was edited');
         });
         return redirect('/users/' . $id)->with(['message' => "User was updated successfully. The new password was sent to his/her email ({$user->email})."]);
     }
     if (Auth::user()->role == "worker" || $id == Auth::user()->id) {
         return redirect('/profile/')->with(['message' => "Data was updated successfully."]);
     }
     return redirect('/users/' . $id)->with(['message' => "User was updated successfully."]);
 }
 public function addUsers($id, Request $request)
 {
     $users = $request->input('users');
     $roster_data = Roster::where('id', '=', $id)->first();
     $roster = Roster::find($id)->users();
     foreach ($users as $user) {
         $roster->attach($user);
         Notification::add($user, 'CREATE_EVENT', ['start' => Common::formatDateTimeForSQL($roster_data->start_time), 'end' => Common::formatDateTimeForSQL($roster_data->end_time), 'admin_id' => Auth::user()->id]);
     }
     return response()->json(Roster::where('id', $id)->with('users')->first()->toArray()['users'], 200);
 }